<html>
<head>
<title>Encode/Decode</title>
</head>
<body>
<h1>Super Encoder/Decoder</h1>
<h3>Instructions</h3>
<p>For Encoding Text:<br /><br />Insert a cleartext string into the text box below marked "Encode". Leave "Decode" blank. Input a whole number of 1 or more in the box marked "Key". The higher the Key value, the string will be more secure as well as long.</p>
<p>For Decoding a code:<br /><br />Insert the encoded string into the text box below marked "Decode". Leave "Encode" blank. Input the Key Value that was used to encode this string into the text box marked "Key". Without this value, the text will not decode properly.</p>
<form method="post" action="encode.php">
<table cellpadding="2" cellspacing="2">
<tr>
<td valign="top">Encode</td>
<td><textarea name="encode" rows="3" cols="40" wrap="virtual"></textarea></td>
</tr>
<tr>
<td valign="top">Decode</td>
<td><textarea name="decode" rows="3" cols="40" wrap="virtual"></textarea></td>
</tr>
<tr>
<td valign="top">Key</td>
<td><input type="text" name="key"></td>
</tr>
<tr>
<td valign="top">Mode</td>
<td>
<select name="mode">
<option value="encode">Encode</option>
<option value="decode">Decode</option>
</select>
</td>
</tr>
<tr>
<td valign="top"></td>
<td><input type="submit" name="submit" value="Encode/Decode"></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['submit']) AND $_POST['submit'] != '')
{
$encode = trim($_POST['encode']);
$decode = trim($_POST['decode']);
$mode = trim($_POST['mode']);
$key = trim($_POST['key']);
if ($encode == '' AND $decode == '')
{
echo '<span style="color: red; font-weight: bold;">Error:</span> Please enter a string to encode/decode.';
}
else if ($key == '' OR preg_match("#([^0-9]+)#", $key))
{
echo '<span style="color: red; font-weight: bold;">Error:</span> Either the key number was left blank, or you\'ve entered an invalid key.';
}
else if ($encode != '' AND $decode != '')
{
echo '<span style="color: red; font-weight: bold;">Error:</span> Cannot encode and decode simultaneously. Please encode/decode individually.';
}
else
{
$data = '';
switch ($mode)
{
case 'encode':
for ($i = 0; $i <= $key; $i++)
{
$data .= base64_encode($encode);
}
$msg = '<font color="red">Final Encoded Value:</font>';
break;
case 'decode':
for ($i = 0; $i <= $key; $i++)
{
$data .= base64_decode($decode);
}
$msg = '<font color="red">Final Decoded Value:</font>';
break;
}
echo $msg.'<br /><br />'.$data;
}
}
?>
</body>
</html>