+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: PHP Code: Simple Encryption Algorithm

  1. #1
    Void's Avatar
    Void is offline Programming Expert
    Join Date
    Jun 2006
    Posts
    410
    Rep Power
    23

    PHP Code: Simple Encryption Algorithm

    This is a very simple Encryption Algorithm that uses the Caesar Shift Decoder (also called the Caesar Cipher).

    The encryption is not limited to 25 characters though but is limited to the ASCII table moving each character a random amount of numbers forward.

    Here is how it works:

    1) Generate a Random Number

    Code:
    // Create a Random Generator
    srand((double)microtime()*1000000); // Seed the Random Generator
    $strCharNumber rand(102,106); // Pics a number between 102 and 106 
    This code will be the variable for how many characters the encryption scheme will be moved forward. As you can see, it is between 102 and 106.

    2) Add this character to our final string output

    Code:
    $strcode chr($strCharNumber); // Add char to ending String 
    This allows us to grab that character and decrypt the entire string. This makes the code very unsecure as anyone that knows that is the decoding character can decode this message.

    3) Encode the rest of the string. Lets say you received a [b]g[/g] which is 103 ascii value. For each character you would get the ascii value and move it up 103 values in the ascii table.

    Code:
    // For Loop to convert each char into ascii then increase number
    for ($i 0$i strlen($name); $i++) {
            
    $strChar ord($name[$i]) + $strCharNumber
    4) In my code I also converted to hex but you can leave this step out if you like.

    Code:
            $strChar bin2hex(chr($strChar)); 
    5) Add the string to the final string and close the for loop.

    Code:
            $strcode $strcode $strChar;
    }
    ?> 
    I've also attached a working copy of the PHP script. Let me know if you have any questions!
    Attached Files Attached Files
    Void

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    I found my "Caesars Cipher" I made a while ago.

    Code:
    <?php

    function CaesarCipher($str$offset=3) {
        
    $max strlen($str);
        for(
    $i 0$i $max$i++){
            
    //if the letter is upper case, keep it uppercase
            
    if(ord($str[$i]) >= 65 && ord($str[$i]) <= 90){
                if((
    ord($str[$i])+$offset) > 90) {
                    
    $crypt .= chr(65+((ord($str[$i])+$offset)-91));
                } else {
                    
    $crypt .= chr(ord($str[$i])+$offset);
                }
            }
            
            
    //if the letter is lower case, keep it lower case
            
    else if(ord($str[$i]) >= 97 && ord($str[$i]) <= 122){
                if((
    ord($str[$i])+$offset) > 122) {
                    
    $crypt .= chr(97+((ord($str[$i])+$offset)-123));
                } else {
                    
    $crypt .= chr(ord($str[$i])+$offset);
                }
            }
            
            else {
                die(
    "You can only use letters.");
                
    //$crypt .= chr(ord($str[$i])+$offset);
            
    }
        }
        
    //$crypt = strtoupper($crypt);
        
    echo $crypt;
    }

    ?>

  4. #3
    technology is offline Newbie
    Join Date
    Oct 2007
    Posts
    1
    Rep Power
    0

    thanks

    I hope this will gonna help

  5. #4
    dfactor is offline Newbie
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Re: thanks

    Quote Originally Posted by technology View Post
    I hope this will gonna help
    This looks like it will work for me!

  6. #5
    yolau is offline Newbie
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Re: PHP Code: Simple Encryption Algorithm

    I was looking for something similar a frew weeks ago. Thanks !

  7. #6
    Amyxxx is offline Newbie
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Re: PHP Code: Simple Encryption Algorithm

    Thank you, that was really helpful!

  8. #7
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: PHP Code: Simple Encryption Algorithm

    Not to bad mate. Is there anyway to retrieve the encryption?
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  9. #8
    Jordan Guest

    Re: PHP Code: Simple Encryption Algorithm

    You have to know the shift value. In void's example it is between 102 and 106.

    Code:
    $strCharNumber = rand(102,106);
    In John's example it defaults to 3 but could be whatever the coder sets it to.

  10. #9
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: PHP Code: Simple Encryption Algorithm

    Oh OK thanks Jordan. How does MD5 work then? How come it's so hard to crack?
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  11. #10
    Jordan Guest

    Re: PHP Code: Simple Encryption Algorithm

    MD5 is a one-way hash algorithm, however, these encryption schemes above just move the ASCII value of a character. For instance, it will take the Char "a" and convert it to the ASCII value of 97, add 3 to it to make 100 and convert it back to a char (100 = d). It is a fairly simple encryption scheme and can be cracked fairly easy.

+ Reply to Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 05-26-2011, 12:58 AM
  2. Replies: 1
    Last Post: 04-02-2011, 11:39 PM
  3. Code:VB6.0 UltraFile Encryption
    By TcM in forum Visual Basic Tutorials
    Replies: 7
    Last Post: 06-21-2009, 01:44 AM
  4. VB6 Encryption Code/Function
    By jfmm2008 in forum Visual Basic Programming
    Replies: 1
    Last Post: 02-03-2009, 06:36 PM
  5. Looking for a simple encoding/encryption method
    By Gezeiten in forum PHP Development
    Replies: 7
    Last Post: 08-05-2008, 05:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts