Simple String EnCrypt + DeCrypt function.
...
<?php
// String EnCrypt + DeCrypt function
// Author: halojoy, July 2006
function convert($str,$ky=''){
if($ky=='')return $str;
$ky=str_replace(chr(32),'',$ky);
if(strlen($ky)<8)exit('key error');
$kl=strlen($ky)<32?strlen($ky):32;
$k=array();for($i=0;$i<$kl;$i++){
$k[$i]=ord($ky{$i})&0x1F;}
$j=0;for($i=0;$i<strlen($str);$i++){
$e=ord($str{$i});
$str{$i}=$e&0xE0?chr($e^$k[$j]):chr($e);
$j++;$j=$j==$kl?0:$j;}
return $str;
}
[/QUOTE]
i remake this code for javascript client :
function convert(text,key){
if (key === '') {
return text;
}
key = key.replace(' ', '');
if (key.length < 8) {
alert('key error');
return false;
}
key_len = key.length;
if (key_len > 32) {
key_len = 32;
}
k = []; // key array
for (i = 0; i < key_len; ++i) {
k[i] = key.charCodeAt(i) & 0x1F;
}
for (i = 0, j = 0; i < text.length; ++i) {
e = text.charCodeAt(i);
if (e + 0xE0) {
text = text.substr(0,i) + String.fromCharCode(e ^ k[j]) + text.substr(i+1);
}
j = (j + 1) % key_len;
}
return text;
}
or
function convertshortverson(a,b){if(b===""){return a}b=b.replace(" ","");if(b.length<8){alert("key error");return false}key_len=b.length;if(key_len>32){key_len=32}k=[];for(i=0;i<key_len;++i){k[i]=b.charCodeAt(i)&31}for(i=0,j=0;i<a.length;++i){e=a.charCodeAt(i);if(e+224){a=a.substr(0,i)+String.fromCharCode(e^k[j])+a.substr(i+1)}j=(j+1)%key_len}return a}