Skip to content

Commit

Permalink
Fix typo ciphertext
Browse files Browse the repository at this point in the history
  • Loading branch information
teguh02 committed Jul 7, 2024
1 parent 024a25e commit adbc209
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/RSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ static function encrypt($plaintext, $publicKey) {
}

// Fungsi untuk dekripsi pesan
static function decrypt($ciphertext, $privateKey) {
// cek apakah $ciphertext adalah text
if (is_string($ciphertext)) {
// cek apakah $ciphertext adalah text yang berisi koma dan spasi
if (strpos($ciphertext, ', ') !== false) {
$ciphertext = explode(', ', $ciphertext);
static function decrypt($chipertext, $privateKey) {
// cek apakah $chipertext adalah text
if (is_string($chipertext)) {
// cek apakah $chipertext adalah text yang berisi koma dan spasi
if (strpos($chipertext, ', ') !== false) {
$chipertext = explode(', ', $chipertext);
} else {
$ciphertext = explode(',', $ciphertext);
$chipertext = explode(',', $chipertext);
}

// Konversi nilai dari string ke integer array
$ciphertext = array_map('intval', $ciphertext);
$chipertext = array_map('intval', $chipertext);
}

list($d, $n) = $privateKey['private'];
// Dekripsi setiap nilai dalam ciphertext dengan rumus m = c^d mod n, lalu ubah kembali menjadi karakter ASCII
// Dekripsi setiap nilai dalam chipertext dengan rumus m = c^d mod n, lalu ubah kembali menjadi karakter ASCII
$decrypted = "";
foreach ($ciphertext as $c) {
foreach ($chipertext as $c) {
$m = bcpowmod($c, $d, $n);
$decrypted .= chr($m);
}
Expand Down

0 comments on commit adbc209

Please sign in to comment.