Sisber Subs Polialphabet

http://hendra.ilkomers.com/peta/poli
itu demonya
kodenya cuma butuh 2 file :

poliHome.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Sistem Berkas Substitusi Polialphabet!</title>
</head>
<body>
Rumus :
<h2>T(i+1)=(aTi + 3) mod m </h2>
<form action=”poliEncoderi.php” method=”POST”>
a  : <input type=”text” name=”a”><br>
c  : <input type=”text” name=”c”><br>
m  : <input type=”text” name=”m”><br>
text : <input type=”text” style=”width: 300px; height: 100px” name=”text”>
<input type=”submit” value=”Encode”>
</form>
</body>
</html>

poliEncoderi.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Encode</title>
</head>
<body>
<?php
$a=$_POST[‘a’];
$c=$_POST[‘c’];
$m=$_POST[‘m’];
$text=$_POST[‘text’];
if($a==null || $c==null || $m==null || $text==null)
{
echo “Warning, ada yang belum anda isi<br>”;
echo ‘a : ‘.$a.'<br>’;
echo ‘c : ‘.$c.'<br>’;
echo ‘m : ‘.$m.'<br>’;
echo ‘text : ‘.$text.'<br>’ ;
}
else
{
echo ‘a : ‘.$a.'<br>’;
echo ‘c : ‘.$c.'<br>’;
echo ‘m : ‘.$m.'<br>’;
echo ‘rumus :> T(i+1)=(‘.$a.’Ti + ‘.$c.’) mod ‘.$m.'<br>’;
echo ‘text : ‘.$text.'<br>’ ;
chiper($a,$c,$m,$text);
}
//generate bil random sesuai m
function generateT($text,$m)
{
$random=rand(1,$m);
$T=$random;
return $T;
}
//melakukan perhitungan T
function countT($a,$c,$m,$text)
{
$T[0]= generateT($text,$m);
for ($i=1;$i<=(strlen($text));$i++)
{
$T[$i]=($a*$T[$i-1]+$c)%$m;
echo ‘T(‘.$i.’)=(‘.$a.’ * ‘.$T[$i-1].’ + ‘.$c.’) mod ‘.$m.’ = ‘.$T[$i].'<br>’;
}
return $T;
}
//melaukuan chipering
function chiper($a,$c,$m,$text)
{
$T=countT($a,$c,$m,$text);
echo “HASIL : “;
echo “<table border=’1′ cellspacing=’5′ cellpadding=’3′>
<tr>”;
for ($i=1;$i<=(strlen($text));$i++)
{
$C[$i]=ord($text[$i-1]);
$Chip[$i]=$C[$i]+$T[$i];
echo ‘<td>’. $Chip[$i].'</td>’;
}
echo “</tr><tr>”;
for ($i=1;$i<=(strlen($text));$i++)
echo ‘<td>’.chr( $Chip[$i]).'</td>’;
echo “</tr></table>”;
}
?>
</body>
</html>


Leave a comment

Your email address will not be published. Required fields are marked *