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”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<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”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<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>


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s