Permutation | +----------------------------------------------------------------------+ | | | | (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="Permutation Encoder and Decoder"; $HEADTITLE="Permutation Encoder and Decoder"; function permute_encode($plain,$permute){ $perm_table=""; $unique_table=1; $perm_len=strlen($permute); $plain=filter($plain); $plain=check_length($plain); for($i=0;$i<$perm_len;$i++){ $k=substr($permute,$i,1); $perm_table[$i]=$k; } for($i=0;$i<$perm_len;$i++){ for($j=$i+1;$j<$perm_len;$j++){ if($perm_table[$i]==$perm_table[$j]){ $unique_table=0; } } } if($unique_table==0){ return "error: Duplicate permutation table detected"; } for($i=0;$i \n"; echo "Enter text you want to encode or decode:
\n"; echo "

\n"; echo "Permute :"; for($i=1;$i<=$MAXPERMUTE;$i++){ echo "\n"; } echo "

"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($process=="Encode"){ $key_table=""; for($i=1;$i<=$MAXPERMUTE;$i++){ $key_table=$key_table.$key[$i]; } $key_table=eregi_replace("0","",$key_table); $cipher=permute_encode($plain,$key_table); echo "Text after permuting $key_table:
\n"; echo "

\n"; }elseif($process=="Decode"){ $key_table=""; for($i=1;$i<=$MAXPERMUTE;$i++){ $key_table=$key_table.$key[$i]; } $key_table=eregi_replace("0","",$key_table); $cipher=permute_decode($plain,$key_table); echo "Text after decoding:
\n"; echo "

\n"; } bottom(); ?>