Monoalphabetic Substitution | +----------------------------------------------------------------------+ | | | | (c) 2002 by M.Abdullah Khaidar (khaidarmak@yahoo.com) | | | | This program is free software. You can redistribute it and/or modify | | it under the terms of the GNU General Public License as published by | | the Free Software Foundation; either version 2 of the License. | | | +----------------------------------------------------------------------+ ************************************************************************/ include "main.php"; $TITLE="Monoalphabetic Substitution Encoder and Decoder"; $HEADTITLE="Monoalphabetic Substitution Encoder and Decoder"; function mono($plain,$key){ $unique_table=1; $detected_table=""; $from="abcdefghijklmnopqrstuvwxyz"; $cipher=""; if(eregi("--",$key)){ return "error: Empty substitution detected"; } for($i=0;$i<=25;$i++){ $k=substr($key,$i,1); $check_table[$i]=$k; } for($i=0;$i<=25;$i++){ for($j=$i+1;$j<=25;$j++){ if($check_table[$i]==$check_table[$j]){ $unique_table=0; $detected_table=$detected_table.ascii_letter($i).ascii_letter($j); } } } $plain=filter($plain); $cipher=strtr($plain,$from,$key); if($unique_table==1){ return $cipher; }else{ $table_error="error: Same substitution table detected:\n"; for($i=0;$i\n"; echo "Enter text you want to encode or decode:
\n"; echo "[- note: lowercase characters and no space -]
\n"; echo "

\n"; echo "\n"; echo "\n"; echo "\n"; for($i=0;$i<=12;$i++){ echo "\n"; } echo "\n"; for($i=0;$i<=12;$i++){ echo "\n"; } echo "\n"; for($i=13;$i<=25;$i++){ echo "\n"; } echo "\n"; for($i=13;$i<=25;$i++){ echo "\n"; } echo "\n"; echo "
Substitution Table :
".ascii_letter($i)."
\n"; echo "\n"; echo "
".ascii_letter($i)."
\n"; echo "\n"; echo "
\n"; echo "

"; echo "\n"; echo "\n"; if ($process=="Encode/Decode"){ $key_table=""; for($i=0;$i<=25;$i++){ $key_table=$key_table.$key[$i]; } $cipher=mono($plain,$key_table); echo "Text after encoding or decoding:
\n"; echo "

\n"; } bottom(); ?>