Zend - The PHP Company




Security

Add Code


TransCrypt Encrytion functions  

Type: code fragment
Added by: Rival7
Entered: 30/11/2001
Last modified: 02/11/2000
Rating: **** (6 votes)
Views: 6252
TransCrypt is an encrytion library. It simply uses look up tables to translate bytes. The look up tables are generated by the LFSR algorithm.


<?
/* 
TransCrypt Encrytion functions

Description: TransCrypt is an encrytion library. It simply uses look up tables to translate bytes. The look up tables are generated by the LFSR algorithm.

Example:

include("trans_crypt.php");
$secret = "I like encrytion";
$crypted_data = trans_encrypt($secret);
$decrypted_data = trans_decrypt($crypted_data);
echo "secret = $decrypted_data";

*/

function trans_encrypt($data){
    for(
$i 0$key 27$c 48$i <= 255$i++){
        
$c 255 & ($key ^ ($c << 1));
        
$table[$key] = $c;
        
$key 255 & ($key 1);
    }
    
$len strlen($data);
    for(
$i 0$i $len$i++){
        
$data[$i] = chr($table[ord($data[$i])]);
    }
    return 
base64_encode($data);
}

function 
trans_decrypt($data){
    
$data base64_decode($data);
    for(
$i 0$key 27$c 48$i <= 255$i++){
        
$c 255 & ($key ^ ($c << 1));
        
$table[$c] = $key;
        
$key 255 & ($key 1);
    }
    
$len strlen($data);
    for(
$i 0$i $len$i++){
        
$data[$i] = chr($table[ord($data[$i])]);
    }
    return 
$data;
}

?>


Usage Example


include("trans_crypt.php");
$secret = "I like encrytion";
$crypted_data = trans_encrypt($secret);
$decrypted_data = trans_decrypt($crypted_data);
echo "secret = $decrypted_data";


Rate This Script





Search



This Category All Categories