Problem With An Array Encoder + Decoder

Status
Not open for further replies.

masterjake

New Member
Messages
73
Reaction score
0
Points
0
Hi guys, I'm having this problem where I want to convert letters to a set of numbers and then convert them back (used to encode messages, send them to someone, then they decode it for fun =]). I had every character in the keyboard stored into the array but I ran into problems so I dropped it down to just a - z until I can get it fixed. When I try to decode the word "hello" which is a series of numbers i usually get something like "he33hr" or something. Here's the code though, can someone help?

Code:
<?php

if ($_GET['action']=="encode")
{

$tocode = $_POST['tocode'];
$message = $_POST['message'];
$letters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
$numbers = array("11", "12", "13", "14", "15", "21", "22", "23", "24", "25", "31", "32", "33", "34", "35", "41", "42", "43", "44", "45", "51", "52", "53", "54", "55", "36");

if ($tocode == "enc")
{
    $errorMessage = str_replace($letters, $numbers, $message);
} else {
$errorMessage = str_replace($numbers, $letters, $message);
}

}

?>
<html>
<head>
<title>QCode</title>
</head>
<body>
<center>
<h1>QCode</h1><hr>
<form action="qcode.php?action=encode" method="post">
<table border="0" cellspacing="0" cellpadding="2">
<tr><td><input type="radio" name="tocode" value="enc" checked> Encode</td></tr>
<tr><td><input type="radio" name="tocode" value="dec"> Decode</td></tr>
<tr><td></td></tr>
<tr><td>Message</td></tr>
<tr><td><textarea cols="60" rows="8" name="message"></textarea></td></tr>
<tr><td align="right"><input type="submit" name="Submit" value=" &raquo; Encode / Decode "></td></tr>
</table>
</form>
<?php

if ($errorMessage)
{

echo "<br><form><table border=0 cellspacing=0 cellpadding=2><tr><td>Output</td></tr><tr><td><textarea cols=60 rows=8>".$errorMessage."</textarea><td></tr></table></form>";

}

?>
<hr>
Created by <a href="http://www.masterjakeonline.com/">Jake "Master Jake" Chappell</a><br>
Copyright &copy; 2008 Jake Chappell. All rights reserved.<br>
QCode created by <a href="http://www.quigly.net/">Quigly</a>
</center>
</body>
</html>
 

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
Hello, we don't give support for scripts. You may try the 3rd party apps and scripts section on our forums and see if you can get help there.
 
Status
Not open for further replies.
Top