954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Encode and Decode without mbstring

0
By cwarn23 on Apr 3rd, 2010 3:40 pm

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);
?>

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You