Hello, I searched the board, and I found someone posted this code. What I think it does it scramble a message using a defined key, and you will then need that key to unscramble it later. This is what I want. I cannot use any of the mcrypt libraries or anything like that because the functions must be able to run with the normal out of the box php, with no additional addons. What I dont understand about this code is why when I change the key, in the encrypt and decrypt function, the integrity of the message is lost.
function encrypt($message,$levels,$skip,$key='c 5x1ag9e0wyzjbl3dmkh82vu6opqir4sn7tf') {
for($i=0;$i<$levels;$i++) {
$len=strlen($message)-($i*2);
$key=substr($key,$skip).substr($key,0,$skip);
$message=strtr(substr($message,0,strlen($message)-$i),"abcdefghijklmnopqrstuvwxyz 1234567890",$key).substr($message,strlen($message)-$i);
}
return $message.str_pad($levels,3,"0",STR_PAD_LEFT).str_pad($skip,2,"0",STR_PAD_LEFT);
}
function decrypt($message,$key='c 5x1ag9e0wyzjbl3dmkh82vu6opqir4sn7tf') {
$skip=substr($message,-2,2);
$levels=substr($message,-5,3);
$message=substr($message,0,-5);
for($i=0;$i<$levels+1;$i++) {
$key=substr($key,$skip).substr($key,0,$skip);
}
for($i=0;$i<$levels;$i++) {
$key=substr($key,-$skip).substr($key,0,37-$skip);
$message=strtr(substr($message,0,strlen($message)-($levels-1-$i)),$key,"abcdefghijklmnopqrstuvwxyz 1234567890").substr($message,strlen($message)-($levels-1-$i));
}
return $message;
}