0

Hi, I have made an encryption and decryption script for those who want to encode data and decode the encoded data. This script may especially be useful for those who do not have the mbstring library installed as it uses a math grid. So for example you can store the encoded data in a text file where nobody can translate it then get php to translate it with the decode function. Enjoy.

<?php
function text_encode($input) {
$arr=str_split($input,1);
$result='';
foreach($arr AS $val) {
    $b=floor(ord($val)/4);
    $a=$b+$b+32+($val%4);
    $b+=64-(ord($val)%4);
    $c=64+(ord($val)%4);
    $result.=chr($a).chr($b).chr($c);
    }
return $result;
}
 
function text_decode($input) {
$arr=str_split($input,3);
$result='';
foreach ($arr AS $group) {
    $sub=str_split($group,1);
    $c=ord($sub[2]);
    $c-=64;
    $b=ord($sub[1]);
    $b-=(64-$c);
    //echo $b;
    $chr=$b*4;
    $chr+=$c;
    $result.=chr($chr);
    }
return $result;
}
 
$text=text_encode('Testing...');
echo text_decode($text);
?>
1
Contributor
0
Replies
1
Views
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.