Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
Oracle Discussion & Chat
 PHP Code: Encrypt and Decrypt without a known key Jump to:  
Category: >> PHP Code >> Encrypt and Decrypt without a known key Bookmark and Share

<< lastnext >>

Snippet Name: Encrypt and Decrypt without a known key

Description: PHP Function to Encrypt and Decrypt a string without a known key.
The string itself has his own different key for every character.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

FUNCTION encrypt_decrypt($Str_Message) { 
    FOR ($Position = 0;$Position<$Len_Str_Message;$Position++){ 
        // long code of the function to explain the algoritm 
        //this function can be tailored by the programmer modifyng the formula 
        //to calculate the key to use for every character in the string. 
        $Key_To_Use = (($Len_Str_Message+$Position)+1); // (+5 or *3 or ^2) 
        //after that we need a module division because can&#65533;t be greater than 255 
        $Key_To_Use = (255+$Key_To_Use) % 255; 
        $Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1); 
        $Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted); 
        $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use;  //xor operation 
        $Encrypted_Byte = CHR($Xored_Byte); 
        $Str_Encrypted_Message .= $Encrypted_Byte; 
        //short code of  the function once explained 
        //$str_encrypted_message .= chr((ord(substr($str_message, $position, 1))) ^ ((255+(($len_str_message+$position)+1)) % 255)); 
    RETURN $Str_Encrypted_Message; 
} //end function 
//sample use of the function 
$Str_Test="This function is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation in any version 
of the License."."<br>"."This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
ECHO $Str_Test."<br>"; 
$Str_Test2 = ENCRYPT_DECRYPT($Str_Test); 
ECHO $Str_Test2."<br><br>"; 
$Str_Test3 = ENCRYPT_DECRYPT($Str_Test2); 
ECHO "<br>".$Str_Test3."<br>"; 

Oracle Magazine
and Oracle White Papers

SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 34 users online    © 2009 psoug.org

Forgot your password?