Page 1 of 1

challenge (and help): reverse this

Posted: Tue Sep 30, 2003 10:59 pm
by adamk

Code: Select all

function do_encrypt($text, $key, $confusion = 3)
{
	global $encrypted;

	for($x=0; $x<=strlen($text)-1; $x++)
	&#123;
		for($y=0; $y<=strlen($key)-1; $y++)
			for($z=0; $z<=$confusion; $z++)
				$encrypted .= substr(base64_encode($text), $x, $z) . substr(base64_encode($key), $y, $z);
	&#125;

	return $encrypted;
&#125;
That code needs to be reversed to give a decrypted version of whatever text is passed to it.

$text is the unencrypted text, $key is the public key used in the encryption/decryptyion process, and $confusion is basically the amount of confusion to add to the generated encrypted text. If you could help me reverse this, then I would be very greatful. If you need more explanation of the confusion variable, then just pm me or contact me on some instant messenger.

Posted: Wed Oct 01, 2003 2:16 am
by volka
probably impossible because not all of the subject is enciphered (you're losing data). This is not entirely true; if you adjust $confusion according to the length of the plaintext it might work but then imho $confusion must be part of the key (which might be wrong, I'm definitely not an expert on ciphers).

Let me illustrate this

Code: Select all

<?php
function do_encrypt($text, $key, $confusion = 3)
{
   global $encrypted;

   for($x=0; $x<=strlen($text)-1; $x++)
   {
      for($y=0; $y<=strlen($key)-1; $y++)
         for($z=0; $z<=$confusion; $z++)
            $encrypted .= substr(base64_encode($text), $x, $z) . substr(base64_encode($key), $y, $z);
   }

   return $encrypted;
}
$encrypted = '';
$text = 'abc000123';
$key = 'a';
echo do_encrypt($text, $key);
echo '<br />', base64_encode($text);
?>
the output is
YYYWYQYWJYQ=WYWJYQWJjYQ=JYJjYQJjMYQ=jYjMYQjMDYQ=MYMDYQMDAYQ=DYDAYQDAwYQ=AYAwYQAwMYQ=wYwMYQwMTYQ=MYMTYQMTIYQ=
YWJjMDAwMTIz
since no transformation on the base64-string takes place there must be a z in the cipher's output but isn't, this information is lost.

Posted: Wed Oct 01, 2003 3:25 pm
by adamk
thanks :). i noticed that something wasn't happening with the output, but i wasn't 100% sure of what it was! thanks again!