I don't remember about its source but you can have the code:
$ralphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$alphabet = $ralphabet . $ralphabet;
function encrypt ($strtoencrypt,$password) {
$strtoencrypt = str_replace("\t","[tab]",$strtoencrypt);
$strtoencrypt = str_replace("\n","[new]",$strtoencrypt);
$strtoencrypt = str_replace("\r","[ret]",$strtoencrypt);
global $ralphabet;
global $alphabet;
for( $i=0; $i<strlen($password); $i++ )
{
$cur_pswd_ltr = substr($password,$i,1);
$pos_alpha_ary[] = substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet));
}
$i=0;
$n = 0;
$nn = strlen($password);
$c = strlen($strtoencrypt);
while($i<$c)
{
$encrypted_string .= substr($pos_alpha_ary[$n],strpos($ralphabet,substr($strtoencrypt,$i,1)),1);
$n++;
if($n==$nn) $n = 0;
$i++;
}
return $encrypted_string;
}
function decrypt ($strtodecrypt,$password) {
global $ralphabet;
global $alphabet;
for( $i=0; $i<strlen($password); $i++ )
{
$cur_pswd_ltr = substr($password,$i,1);
$pos_alpha_ary[] = substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet));
}
$i=0;
$n = 0;
$nn = strlen($password);
$c = strlen($strtodecrypt);
while($i<$c) {
$decrypted_string .= substr($ralphabet,strpos($pos_alpha_ary[$n],substr($strtodecrypt,$i,1)),1);
$n++;
if($n==$nn) $n = 0;
$i++;
}
$decrypted_string = str_replace("[tab]","\t", $decrypted_string);
$decrypted_string = str_replace("[new]","\n", $decrypted_string);
$decrypted_string = str_replace("[ret]","\r", $decrypted_string);
return $decrypted_string;
}
Note: Only characters in $ralphabet will be encrypted or decrypted properly. Eg: Presently it doesnt have a ; (semi-colon), it you encrypt (😉 it will do so, but will not decrypt the encrypted to (😉 .
Also you must pass $password same as the one used for encrypting to decrypt properly. Works similar to crypt function 🙂