niallniall Posted November 11, 2007 Share Posted November 11, 2007 Hello, A couple of people on here helped me make this yesterday: http://www.onlineworx.net/testing/gen1.php It basically lets my encrypt sensitive information to passed around to my colleagues safely over the internet via email and instant messaging etc. I give trusted partners a copy of this to store locally and they can safely decrypt the information when it arrives. I need the thing to be able to differentiate between capital and non capital letters but I cant figure out how to do it. Here's the code: <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Make a password to send:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="encrypt"/> </form> <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Unscramble password:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="decrypt"/> <p> <?php if ($_POST['submit'] == "encrypt") { $user_junk = strtolower($_POST['user_junk']); $coded = ""; for ($i=0;$i<strlen($user_junk);$i++) { $char = $user_junk{$i}; if ($char == "z") $char = "`"; // forced roll z to a if ($char == "9") $char = "/"; // forced roll 9 to 0 $coded.= chr(ord($char) + 1); } echo "Encryted Password:<br>".$coded. "<br/><br/>"; } if ($_POST['submit'] == "decrypt") { $user_junk = strtolower($_POST['user_junk']); $coded = ""; for ($i=0;$i<strlen($user_junk);$i++) { $char = $user_junk{$i}; if ($char == "a") $char = "{"; // forced roll z to a if ($char == "0") $char = ":"; // forced roll 0 to 9 $coded.= chr(ord($char) - 1); } echo "Decrypted Password:<br>".stripslashes($coded). "<br/><br/>"; } ?> Here's how I thought I could make it work! But alas it doesn't work. <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Make a password to send:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="encrypt"/> </form> <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Unscramble password:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="decrypt"/> <p> <?php if ($_POST['submit'] == "encrypt") { $user_junk = strtolower($_POST['user_junk']); $coded = ""; for ($i=0;$i<strlen($user_junk);$i++) { $char = $user_junk{$i}; if ($char == "z") $char = "`"; // forced roll z to a if ($char == "9") $char = "/"; // forced roll 9 to 0 $coded.= chr(ord($char) + 1); } echo "Encryted Password:<br>".$coded. "<br/><br/>"; } if ($_POST['submit'] == "decrypt") { $user_junk = strtolower($_POST['user_junk']); $coded = ""; for ($i=0;$i<strlen($user_junk);$i++) { $char = $user_junk{$i}; if ($char == "a") $char = "{"; // forced roll z to a if ($char == "0") $char = ":"; // forced roll 0 to 9 $coded.= chr(ord($char) - 1); } echo "Decrypted Password:<br>".stripslashes($coded). "<br/><br/>"; } ?> Can one of you please help me get this thing to treat capitals and non capitals seperately. Any help would me much appreciated. Cheers Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 11, 2007 Author Share Posted November 11, 2007 anyone? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 11, 2007 Share Posted November 11, 2007 First of all, if you really need encrypting / decrypting to transfer sensitive information, don't use so simple encoding-decoding methods... Check mCrypt. Anyway, you are applying strtolower() on the input so it's all going to be small case. I'd do it this way tho: <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Make a password to send:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="encrypt"/> </form> <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Unscramble password:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="decrypt"/> <p> <?php $chars[0] = array_merge(range(65,90), range(97,122), range(48,57)); $chars[1] = array_merge(range(66,90), array(65), range(98,122), array(97), range(49,57), array(48)); array_walk($chars[0], "chr2"); array_walk($chars[0], "chr2"); if ($_POST['submit'] == "encrypt") { $coded = str_replace($chars[0], $chars[1], $_POST['user_junk']); echo "Encryted Password:<br>".$coded. "<br/><br/>"; } if ($_POST['submit'] == "decrypt") { $coded = str_replace($chars[1], $chars[0], $_POST['user_junk']); echo "Decryted Password:<br>".$coded. "<br/><br/>"; } function chr2 (&$a) { $a = chr($a); } ?> EDIT- for some reason it doesn't work, I'll check it later tho. Orio. Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 12, 2007 Author Share Posted November 12, 2007 Did you get it to work? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 12, 2007 Share Posted November 12, 2007 lol it was more complicated than I've thought, I guess I was just thinking wrong. And I've learned something about str_replace()... Anyway, this works: <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Make a password to send:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="encrypt"/> </form> <form action=" <?=$_SERVER['PHP_SELF']?>" method="post"> Unscramble password:<br /> <textarea name="user_junk" cols="20" rows="1"> </textarea> <input type="submit" name="submit" value="decrypt"/> <p> <?php if(!isset($_POST['submit'])) die; $chars = array(); $regular = array_merge(range(65,90), range(97,122), range(48,57)); $temp[0] = array_merge(array(90), range(65,89), array(122), range(97,121), array(48), range(48,56)); $temp[1] = array_merge(range(66,90), array(65), range(98,122), array(97), range(49,57), array(48)); for($i=0; $i<count($temp[0]); $i++) { $chars[0][$regular[$i]] = $temp[0][$i]; $chars[1][$regular[$i]] = $temp[1][$i]; } $coded = ""; $method = ($_POST['submit'] == "encrypt") ? 1 : 0; for($i=0; $i<strlen($_POST['user_junk']); $i++) { $char = ord($_POST['user_junk']{$i}); if(isset($chars[$method][$char])) $coded .= chr($chars[$method][$char]); } if($method == 1) echo "Encryted Password:<br>".$coded. "<br/><br/>"; else echo "Decryted Password:<br>".$coded. "<br/><br/>"; ?> Enjoy, Orio. Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 13, 2007 Author Share Posted November 13, 2007 This is my first time with a problem on this forum and I am complete php noobie. In less than a day members here have solved three different problems for me. Wow this forum is brilliant keep up the good work guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.