Website challenge!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Website challenge!

Post by Joe »

I have recently been trying to make a small decryption challenge for my site where the user has to work out the encryption method used. To help people out I have developed a tool which takes a string and subtracts 2 away from each character (Ascii shift). The problem is that I cannot get it to work on the whole string but a single character shift is easy. Any help appreciated!

CODE
====
$string = $_POST['encrypt'];
for ($i=0; $i<strlen($string); $i++)
{
$enc = ord($string) - 2;
$enc1 = chr(substr($enc),$i);
echo $enc1;
}


Regards


Joe 8)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php
for($x = 0; $x < strlen($string); $x++)
{
$string{$x} = chr(ord($string{$x})-2);
}
?>
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Thanks alot man that worked perfect.

Joe 8)
Post Reply