i found some encryption code that was wrote in javascript.
I'd like to mimic it in PHP.
the original code is
function let(grandfather,alchemy,tree) {
grandfather += ' ';
var biologist = grandfather.length;
var horse = 0;
var drawer = '';
for(var cavern = 0; cavern < biologist; cavern++) {
horse = 0;
while(grandfather.charCodeAt(cavern) != 32) {
horse = horse * 10;
horse = horse + grandfather.charCodeAt(cavern)-48;
cavern++;
}
drawer += String.fromCharCode(shake(horse,alchemy,tree));
}
if (arguments[3]) {
drawer += arguments[3];
}
parent.location = 'm'+'a'+'i'+'l'+'t'+'o'+':'+drawer;
}
function shake(people,farm,historian) {
if (historian % 2 == 0) {
mathematical = 1;
for(var message = 1; message <= historian/2; message++) {
memory = (people*people) % farm;
mathematical = (memory*mathematical) % farm;
}
} else {
mathematical = people;
for(var member = 1; member <= historian/2; member++) {
memory = (people*people) % farm;
mathematical = (memory*mathematical) % farm;
}
}
return mathematical;
}
what i've tried to do so far , but isnt working is
<?PHP
function let($encoded, $pseed,$seed) {
$encoded += ' ';
$charstodo = strlen($encoded);
$curr = 0;
$deciphered = '';
for($i = 0; $i < $charstodo; $i++)
{
$curr = 0;
echo ord($encoded{$i})."\n";
while(ord($encoded{$i}) != 32)
{
$curr = $curr * 10;
$curr = $curr + ord($encoded{$i})-48;
$i++;
}
$deciphered += chr(shake($curr,$pseed,$seed));
}
if (arguments[3]) {
$deciphered += arguments[3];
}
return($deciphered);
}
function shake($curr,$pseed,$seed)
{
if ($seed % 2 == 0)
{
$math = 1;
for($i = 1; $i <= $seed/2; $i++) {
$temp = ($curr*$curr) % $pseed;
$math = ($temp*$math) % $pseed;
}
} else {
$math = $curr;
for($i = 1; $i <= $seed/2; $i++) {
$temp = ($curr*$curr) % $pseed;
$math = ($temp*$math) % $pseed;
}
}
return $math;
}
can someone please help me by showing me what i did wrong?
thanks in advance.
UPDATE: Got it working with this. was close!
function let($encoded, $pseed,$seed) {
$encoded = $encoded . ' ';
$charstodo = strlen($encoded);
$curr = 0;
$deciphered = '';
for($i = 0; $i < $charstodo; $i++)
{
$curr = 0;
while(ord($encoded{$i}) != 32)
{
$curr = $curr * 10;
$curr = $curr + ord($encoded{$i})-48;
$i++;
}
$deciphered = $deciphered . chr(shake($curr,$pseed,$seed));
}
return($deciphered);
}
function shake($curr,$pseed,$seed)
{
if ($seed % 2 == 0)
{
$math = 1;
for($i = 1; $i <= $seed/2; $i++) {
$temp = ($curr*$curr) % $pseed;
$math = ($temp*$math) % $pseed;
}
} else {
$math = $curr;
for($i = 1; $i <= $seed/2; $i++) {
$temp = ($curr*$curr) % $pseed;
$math = ($temp*$math) % $pseed;
}
}
return $math;
}