I am doing my school homework, its polybius square cipher. I have already done encryption off input string, but i dont know how to decrypt output string back to input string (aka how to decrypt).
First, i include main php file:
<?php
for ($i=1; $i<=7; $i++)
{
for ($j=1; $j<=7; $j++)
{
if (chr($j+7*($i-1)+47))
$coords[chr($j+7*($i-1)+47)]=$i.$j;
else
$coords[chr($j+7*($i-1)+47)]=$i.$j;
}
}
$input=str_split(strtoupper($text));
$c=count($input);
$output='';
for ($i=0; $i<$c;$i++)
if ($input[$i]!=' ')
$output.=$coords[$input[$i]];
else
$output.=' ';
$search = array('1', '2', '3', '4', '5', '6', '7');
$replace = array('A', 'B', 'C', 'D', 'E', 'F', 'G');
$output = str_replace($search, $replace, $output);
?>
to this html file:
<form action="?page=polybius" method="post">
<textarea name="text"><?= $_POST[$text]; ?><?php echo $output;?></textarea><br/>
<input type="submit" name=cipher" value=" cipher "/><br><br>
</form>
I would like to decode $output back to $input
- encryption: A = $coords of A in polybius square
- decryption: $coords of A = to A
(like this simple caesar cipher code: http://ift.tt/1CrWiVe
Thank you for any suggestions.
Aucun commentaire:
Enregistrer un commentaire