Jump to content

Decoding this piece of PHP code!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
master131

master131

    Newbie

  • Members
  • Pip
  • 1 posts
My friend gave me a piece of encoded PHP code. I decoded it and I got this:
function rotencode($string,$amount) { $key = substr($string, 0, 1); if(strlen($string)==1) { return chr(ord($key) + $amount); } else { return chr(ord($key) + $amount) . rotEncode(substr($string, 1, strlen($string)-1), $amount); }}

He said I am supposed to find a variable and a code like this:

$variablename = 123324234;

Any ideas?

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
I have no idea what you are taking about.

#3
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
LOL

#4
chad

chad

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
function rotencode($string,$amount)
{
	$key = substr($string, 0, 1);
	
	if(strlen($string)==1)
	{
		return chr(ord($key) + $amount);
	}
	else
	{
		return chr(ord($key) + $amount) . rotEncode(substr($string, 1, strlen($string)-1), $amount);
	}
}

i dont get it at all XD

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
What it does is that it adds $amount to all character values in the string, and it does it recursively.

so if you call:
rotEncode("12345", 3), it will return "45678"
rotEncode("ABCDE", 5), it will return "FGHIJ"
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#6
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Very discriptive post, (Y).