I'm trying to do some simple XOR encoding and my functions don't seem to be working correctly. I'm not getting the same thing out that I'm putting in. Can anyone see what I'm missing?
Below are my functions:
Basically to encode I run doit() and the strToHex() and to decode I run hexToStr() and then doit().PHP Code:function hexToStr($hex){
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2){
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
function strToHex($string){
$hex='';
for ($i=0; $i < strlen($string); $i++){
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function doit($key,$text){
$outText='';
for($i=0;$i<strlen($text);){
for($j=0;$j<strlen($key);$j++,$i++){
@$outText .= $text{$i} ^ $key{$j};
}
}
return $outText;
}
Thanks...






Bookmarks