niallniall Posted November 10, 2007 Share Posted November 10, 2007 I want to make a simple code generator for my colleagues and I. The idea is a give them a simple form in which they can enter a code into a box and press submit. They will be presented with the deciphered message. All I want to do is replace letters with numbers or something else that is very simple. I have hardly any php knowledge and any pointers would be really helpful. Cheers Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 10, 2007 Author Share Posted November 10, 2007 Ok Here is what I have so far I just need some help with the PHP bit to make this work. I only want to make the simplest codes possible. http://www.onlineworx.net/testing/gen.html Quote Link to comment Share on other sites More sharing options...
grlayouts Posted November 10, 2007 Share Posted November 10, 2007 firstly you must set out a rule.. ie 1=a 2=b, whats the code you have so far. Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 10, 2007 Author Share Posted November 10, 2007 OK got it working a bit. http://www.onlineworx.net/testing/gen.php Heres the code results page ?php $code = $_REQUEST['code']; $code1 = $_REQUEST['code1']; $code2 = $_REQUEST['code2']; $code3 = $_REQUEST['code3']; $code4 = $_REQUEST['code4']; $code5 = $_REQUEST['code5']; $code6 = $_REQUEST['code6']; // newsagent if ($code == 'a' ) { echo 'b'; } elseif ($code == 'b' ) { echo 'c'; } elseif ($code == 'c' ) { echo 'd'; } elseif ($code == 'd' ) { echo 'e'; } elseif ($code == 'e' ) { echo 'f'; } elseif ($code == 'f' ) { echo 'g'; } elseif ($code == 'g' ) { echo 'h'; } elseif ($code == 'h' ) { echo 'i'; } elseif ($code == 'i' ) { echo 'j'; } elseif ($code == 'j' ) { echo 'k'; } elseif ($code == 'k' ) { echo 'l'; } elseif ($code == 'l' ) { echo 'm'; } elseif ($code == 'm' ) { echo 'n'; } elseif ($code == 'n' ) { echo 'o'; } elseif ($code == '0' ) { echo 'p'; } elseif ($code == 'p' ) { echo 'q'; } elseif ($code == 'q' ) { echo 'r'; } elseif ($code == 'r' ) { echo 's'; } elseif ($code == 's' ) { echo 't'; } elseif ($code == 't' ) { echo 'u'; } elseif ($code == 'u' ) { echo 'v'; } elseif ($code == 'v' ) { echo 'w'; } elseif ($code == 'w' ) { echo 'x'; } elseif ($code == 'x' ) { echo 'y'; } elseif ($code == 'y' ) { echo 'z'; } elseif ($code == 'z' ) { echo 'a'; } if ($code1 == 'a' ) { echo 'b'; } elseif ($code1 == 'b' ) { echo 'c'; } elseif ($code1 == 'c' ) { echo 'd'; } elseif ($code1 == 'd' ) { echo 'e'; } elseif ($code1 == 'e' ) { echo 'f'; } elseif ($code1 == 'f' ) { echo 'g'; } elseif ($code1 == 'g' ) { echo 'h'; } elseif ($code1 == 'h' ) { echo 'i'; } elseif ($code1 == 'i' ) { echo 'j'; } elseif ($code1 == 'j' ) { echo 'k'; } elseif ($code1 == 'k' ) { echo 'l'; } elseif ($code1 == 'l' ) { echo 'm'; } elseif ($code1 == 'm' ) { echo 'n'; } elseif ($code1 == 'n' ) { echo 'o'; } elseif ($code1 == '0' ) { echo 'p'; } elseif ($code1 == 'p' ) { echo 'q'; } elseif ($code1 == 'q' ) { echo 'r'; } elseif ($code1 == 'r' ) { echo 's'; } elseif ($code1 == 's' ) { echo 't'; } elseif ($code1 == 't' ) { echo 'u'; } elseif ($code1 == 'u' ) { echo 'v'; } elseif ($code1 == 'v' ) { echo 'w'; } elseif ($code1 == 'w' ) { echo 'x'; } elseif ($code1 == 'x' ) { echo 'y'; } elseif ($code1 == 'y' ) { echo 'z'; } elseif ($code1 == 'z' ) { echo 'a'; } if ($code2 == 'a' ) { echo 'b'; } elseif ($code2 == 'b' ) { echo 'c'; } elseif ($code2 == 'c' ) { echo 'd'; } elseif ($code2 == 'd' ) { echo 'e'; } elseif ($code2 == 'e' ) { echo 'f'; } elseif ($code2 == 'f' ) { echo 'g'; } elseif ($code2 == 'g' ) { echo 'h'; } elseif ($code2 == 'h' ) { echo 'i'; } elseif ($code2 == 'i' ) { echo 'j'; } elseif ($code2 == 'j' ) { echo 'k'; } elseif ($code2 == 'k' ) { echo 'l'; } elseif ($code2 == 'l' ) { echo 'm'; } elseif ($code2 == 'm' ) { echo 'n'; } elseif ($code2 == 'n' ) { echo 'o'; } elseif ($code2 == '0' ) { echo 'p'; } elseif ($code2 == 'p' ) { echo 'q'; } elseif ($code2 == 'q' ) { echo 'r'; } elseif ($code2 == 'r' ) { echo 's'; } elseif ($code2 == 's' ) { echo 't'; } elseif ($code2 == 't' ) { echo 'u'; } elseif ($code2 == 'u' ) { echo 'v'; } elseif ($code2 == 'v' ) { echo 'w'; } elseif ($code2 == 'w' ) { echo 'x'; } elseif ($code2 == 'x' ) { echo 'y'; } elseif ($code2 == 'y' ) { echo 'z'; } elseif ($code2 == 'z' ) { echo 'a'; } if ($code3 == 'a' ) { echo 'b'; } elseif ($code3 == 'b' ) { echo 'c'; } elseif ($code3 == 'c' ) { echo 'd'; } elseif ($code3 == 'd' ) { echo 'e'; } elseif ($code3 == 'e' ) { echo 'f'; } elseif ($code3 == 'f' ) { echo 'g'; } elseif ($code3 == 'g' ) { echo 'h'; } elseif ($code3 == 'h' ) { echo 'i'; } elseif ($code3 == 'i' ) { echo 'j'; } elseif ($code3 == 'j' ) { echo 'k'; } elseif ($code3 == 'k' ) { echo 'l'; } elseif ($code3 == 'l' ) { echo 'm'; } elseif ($code3 == 'm' ) { echo 'n'; } elseif ($code3 == 'n' ) { echo 'o'; } elseif ($code3 == '0' ) { echo 'p'; } elseif ($code3 == 'p' ) { echo 'q'; } elseif ($code3 == 'q' ) { echo 'r'; } elseif ($code3 == 'r' ) { echo 's'; } elseif ($code3 == 's' ) { echo 't'; } elseif ($code3 == 't' ) { echo 'u'; } elseif ($code3 == 'u' ) { echo 'v'; } elseif ($code3 == 'v' ) { echo 'w'; } elseif ($code3 == 'w' ) { echo 'x'; } elseif ($code3 == 'x' ) { echo 'y'; } elseif ($code3 == 'y' ) { echo 'z'; } elseif ($code3 == 'z' ) { echo 'a'; } if ($code4 == 'a' ) { echo 'b'; } elseif ($code4 == 'b' ) { echo 'c'; } elseif ($code4 == 'c' ) { echo 'd'; } elseif ($code4 == 'd' ) { echo 'e'; } elseif ($code4 == 'e' ) { echo 'f'; } elseif ($code4 == 'f' ) { echo 'g'; } elseif ($code4 == 'g' ) { echo 'h'; } elseif ($code4 == 'h' ) { echo 'i'; } elseif ($code4 == 'i' ) { echo 'j'; } elseif ($code4 == 'j' ) { echo 'k'; } elseif ($code4 == 'k' ) { echo 'l'; } elseif ($code4 == 'l' ) { echo 'm'; } elseif ($code4 == 'm' ) { echo 'n'; } elseif ($code4 == 'n' ) { echo 'o'; } elseif ($code4 == '0' ) { echo 'p'; } elseif ($code4 == 'p' ) { echo 'q'; } elseif ($code4 == 'q' ) { echo 'r'; } elseif ($code4 == 'r' ) { echo 's'; } elseif ($code4 == 's' ) { echo 't'; } elseif ($code4 == 't' ) { echo 'u'; } elseif ($code4 == 'u' ) { echo 'v'; } elseif ($code4 == 'v' ) { echo 'w'; } elseif ($code4 == 'w' ) { echo 'x'; } elseif ($code4 == 'x' ) { echo 'y'; } elseif ($code4 == 'y' ) { echo 'z'; } elseif ($code4 == 'z' ) { echo 'a'; } if ($code5 == 'a' ) { echo 'b'; } elseif ($code5 == 'b' ) { echo 'c'; } elseif ($code5 == 'c' ) { echo 'd'; } elseif ($code5 == 'd' ) { echo 'e'; } elseif ($code5 == 'e' ) { echo 'f'; } elseif ($code5 == 'f' ) { echo 'g'; } elseif ($code5 == 'g' ) { echo 'h'; } elseif ($code5 == 'h' ) { echo 'i'; } elseif ($code5 == 'i' ) { echo 'j'; } elseif ($code5 == 'j' ) { echo 'k'; } elseif ($code5 == 'k' ) { echo 'l'; } elseif ($code5 == 'l' ) { echo 'm'; } elseif ($code5 == 'm' ) { echo 'n'; } elseif ($code5 == 'n' ) { echo 'o'; } elseif ($code5 == '0' ) { echo 'p'; } elseif ($code5 == 'p' ) { echo 'q'; } elseif ($code5 == 'q' ) { echo 'r'; } elseif ($code5 == 'r' ) { echo 's'; } elseif ($code5 == 's' ) { echo 't'; } elseif ($code5 == 't' ) { echo 'u'; } elseif ($code5 == 'u' ) { echo 'v'; } elseif ($code5 == 'v' ) { echo 'w'; } elseif ($code5 == 'w' ) { echo 'x'; } elseif ($code5 == 'x' ) { echo 'y'; } elseif ($code5 == 'y' ) { echo 'z'; } elseif ($code5 == 'z' ) { echo 'a'; } if ($code6 == 'a' ) { echo 'b'; } elseif ($code6 == 'b' ) { echo 'c'; } elseif ($code6 == 'c' ) { echo 'd'; } elseif ($code6 == 'd' ) { echo 'e'; } elseif ($code6 == 'e' ) { echo 'f'; } elseif ($code6 == 'f' ) { echo 'g'; } elseif ($code6 == 'g' ) { echo 'h'; } elseif ($code6 == 'h' ) { echo 'i'; } elseif ($code6 == 'i' ) { echo 'j'; } elseif ($code6 == 'j' ) { echo 'k'; } elseif ($code6 == 'k' ) { echo 'l'; } elseif ($code6 == 'l' ) { echo 'm'; } elseif ($code6 == 'm' ) { echo 'n'; } elseif ($code6 == 'n' ) { echo 'o'; } elseif ($code6 == '0' ) { echo 'p'; } elseif ($code6 == 'p' ) { echo 'q'; } elseif ($code6 == 'q' ) { echo 'r'; } elseif ($code6 == 'r' ) { echo 's'; } elseif ($code6 == 's' ) { echo 't'; } elseif ($code6 == 't' ) { echo 'u'; } elseif ($code6 == 'u' ) { echo 'v'; } elseif ($code6 == 'v' ) { echo 'w'; } elseif ($code6 == 'w' ) { echo 'x'; } elseif ($code6 == 'x' ) { echo 'y'; } elseif ($code6 == 'y' ) { echo 'z'; } elseif ($code6 == 'z' ) { echo 'a'; } ?> cipher is simple - a=b b=c and so on I wanted to be able to type the code all into one box though and could not work out how to do it. Any help would be much appreciated. Cheers Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 10, 2007 Author Share Posted November 10, 2007 Can someone please give me some advice on this? I'm sure I've gone a long way round to achieve what I have so far. I'd like the code all to go into the same field instead of a separate field one for each character. Please help me someone Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 10, 2007 Share Posted November 10, 2007 Perhaps this would help: <?php if (isset($_POST['submit'])) { $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 $coded.= chr(ord($char) + 1); } echo $user_junk. " becomes ". $coded. "<br/><br/>"; } ?> <form method="post"> Enter string to code <input type="text" name="user_junk"/> <input type="submit" name="submit" value="go"/> </form> Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 10, 2007 Author Share Posted November 10, 2007 Here it is : Doesn't show the result. How would I get the results to display in the same page? Thanks for your help so far. I don't understand your php but I'm happy all the same Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 10, 2007 Share Posted November 10, 2007 Doesn't show the result. As posted it works perfectly. Perhaps you've added it to your code improperly. Without seeing yours, who knows? How would I get the results to display in the same page? As posted, that's exactly what it does Thanks for your help so far. I don't understand your php but I'm happy all the same All explained in the manual Quote Link to comment Share on other sites More sharing options...
atlanta Posted November 10, 2007 Share Posted November 10, 2007 Here is some code that might help you thank AndyB for it i just edited a little to do the decrypting .. <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Enter string to code:<br> <textarea name="user_junk" cols="20" rows="10"> </textarea> <input type="submit" name="submit" value="encrypt"/> </form> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Enter string to decode:<br> <textarea name="user_junk" cols="20" rows="10"> </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 $coded.= chr(ord($char) + 1); } echo "Encryted Message:<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 = "z"; // forced roll z to a if ($char != "z") { $coded.= chr(ord($char) - 1); } else { $coded.= chr(ord($char)); } } echo "Decryted Message:<br>".stripslashes($coded). "<br/><br/>"; } ?> </p> EDIT: CHANGED so that when z is used it can be decrypted. also added character support Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 11, 2007 Author Share Posted November 11, 2007 Thank you so much guys. Atlanta you solved my problem thanks very much. Just one more thing; i need to add number 0-9 along side the letters. would you mind showing me how? I feel cheeky asking but I've struggled with this all day and I really want to learn php. Thanks again Quote Link to comment Share on other sites More sharing options...
atlanta Posted November 11, 2007 Share Posted November 11, 2007 heres the new code. Recoded it. <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Enter string to code:<br> <textarea name="user_junk" cols="20" rows="10"> </textarea> <input type="submit" name="submit" value="encrypt"/> </form> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Enter string to decode:<br> <textarea name="user_junk" cols="20" rows="10"> </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 Message:<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 "Decryted Message:<br>".stripslashes($coded). "<br/><br/>"; } ?> </p> Quote Link to comment Share on other sites More sharing options...
niallniall Posted November 11, 2007 Author Share Posted November 11, 2007 Thanks you once again it works just the way I wanted it too. You guys are brilliant. Quote Link to comment Share on other sites More sharing options...
atlanta Posted November 11, 2007 Share Posted November 11, 2007 Np anytime.. click the topic solved button if that answered your question 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.