Created
December 13, 2010 05:27
-
-
Save sakti/738688 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Enkripsi rsa</title> | |
</head> | |
<body> | |
<?php | |
ini_set("memory_limit","32M"); | |
include("generate.php"); | |
// FUNGSI ENKRIPSI | |
$teks=$_POST['plainteks']; | |
if($_POST['enkrip']) | |
{ | |
for($i=0;$i<strlen($teks);++$i) | |
{ | |
$hasilenkripsi.=gmp_strval(gmp_mod(gmp_pow(ord($teks[$i]),$e),$n)); | |
if($i!=strlen($teks)-1) | |
{ | |
$hasilenkripsi.="."; | |
} | |
} | |
} | |
//FUNGSI DESKRIPSI | |
$time_start = microtime(true); | |
$deskripsi=explode(".", $hasilenkripsi); | |
if($deskripsi[0]){ | |
foreach($deskripsi as $nilai) | |
{ | |
$hasildeskripsi.=chr(gmp_strval(gmp_mod(gmp_pow($nilai,gmp_strval($d)),$n))); | |
} | |
} | |
$time_end = microtime(true); | |
$time = $time_end - $time_start; | |
?> | |
<table align="left" border="0" cellspacing="0" cellpadding="2"> | |
<form action="<? $PHPSELF;?>" method="post"> | |
<tr> | |
<td>Plaintext</td> | |
<td> | |
<textarea name="plainteks" rows="5" cols="25" ><?=$teks;?></textarea> | |
</td> | |
<td colspan="2"><?= $msg_null;?></td> | |
</tr> | |
<tr> | |
<td> </td><td> <input type="submit" name="enkrip" | |
value="enkrip"></td> | |
</tr> | |
<tr><td> </td></tr> | |
<tr> | |
<td>Cipertext</td> | |
<td> | |
<textarea name="cipertext" rows="5" cols="25" readonly="readonly" ><?= $hasilenkripsi;?></textarea> | |
</td> | |
<td rowspan="2" valign="top"> | |
</td> | |
</tr> | |
<tr> | |
<td>Hasil deskripsi kembali (Plaintext)</td> | |
<td> | |
<textarea name="decode" rows="5" cols="25" readonly="readonly" ><?=$hasildeskripsi;?></textarea> | |
</td> | |
</tr> | |
<tr> | |
<td> | |
<?php | |
echo "waktu dekripsi: $time <br>"; | |
if($hasildeskripsi == $teks){ | |
echo "Success: true"."</pre>\n"; | |
}else{ | |
echo "Success: false"."</pre>\n"; | |
} | |
?> | |
</td> | |
</tr> | |
</form> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment