Implementasi Kriptografi (Algoritma Vigenere)
index.php
<?php
if($_POST['vigenere']){
$tabel = array(
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z");
$panjangtabel = count($tabel);
$text=strtoupper($_POST['text']);$key=strtoupper($_POST['kunci']);// ambil dari aksi proses
$panjang_text = strlen($text)+1;//panjang text
$panjang_key = strlen($text);//panjang text // untuk bagi replete
$r=($panjang_text / $panjang_key)+ 1 ; //hit untuk key
$keykey=str_repeat($key,$r);//repleat key
$ptn=$panjang_text-1;
$kunci=substr($keykey,0,$ptn);//kunci di potong sepanjang text
//mengulang isi text
$te="0";
for ($i=1;$i<$panjang_text;$i++){
$a = substr($text,$te,1);//untuk tek
$k = substr($kunci,$te,1);//untuk tek
//lihat nilai huruf
for ($hu=1;$hu<$panjangtabel;$hu++){
if ( $a == $tabel[$hu])//mencari nilai text pada array
{$arrayt[]=$hu;}
}
for ($hu=1;$hu<$panjangtabel;$hu++){
if ( $k == $tabel[$hu])//mencari nilai text pada array
{$arrayk[]=$hu;}
}
$te=$te+1;
}
////////////////////////////////////////////////////////////////////////////////
$fusion=array(($arrayt),($arrayk));// gabung array
if($_POST['vigenere'] == "e"){
$ce="0";
for ($dr=1;$dr<$panjang_text;$dr++){
$has=($fusion[0][$ce] + $fusion[1][$ce]);
if($has > 26)// ambil modulus
{$has = $has - 26;}
$arrayhas[]=$has;
$ce=$ce+1;
}
}else
{
$ce="0";
for ($dr=1;$dr<$panjang_text;$dr++){
$has=($fusion[0][$ce] - $fusion[1][$ce]);
if($has < 0)// ambil modulus
{$has = $has + 26;}
$arrayhas[]=$has;
$ce=$ce+1;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
$ok=0;while ($ok < $panjang_text)
{$as = $arrayhas[$ok];
$hasil .= $tabel[$as];
$ok++;
}
$text = $hasil;// hasil akhir
}
?>
<style type="text/css">
.putih {
color: #FFF;
}
</style>
<title>Vigenere Sederhana</title>
<body bgcolor="#CCCCCC"><form name="ok" method="post" action="index.php">
<div align="center">
<p> </p>
<p><strong>Algoritma Vigenere</strong></p>
<table width="200" border="0" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#000000" class="putih" ><strong>Text</strong></td>
<td ><input type="text" name="text" value="<? echo $text; ?>"></td>
</tr>
<tr>
<td bgcolor="#000000" class="putih" ><strong>Kunci</strong></td>
<td><input type="text" name="kunci" value="<? echo $key; ?>"></td>
</tr>
<tr>
<td colspan="2">
<input type="radio" name="vigenere" value="e">
Enkripsi
<input type="radio" name="vigenere" value="d">
Deskripsi
</td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="Proses">||<input type="reset" value="Reset">
</div></td>
</tr>
</table>
<p></p>
</div>
</form>