Sunday, July 28, 2024

Chiper Crypto Sample With PHP

 <?php

function Cipher($ch, $key)

{

if (!ctype_alpha($ch))

return $ch;

$offset = ord(ctype_upper($ch) ? 'A' : 'a');

return chr(fmod(((ord($ch) + $key) - $offset), 26) + $offset);

}

function Encipher($input, $key)

{

$output = "";

$inputArr = str_split($input);

foreach ($inputArr as $ch)

$output .= Cipher($ch, $key);

return $output;

}

function Decipher($input, $key)

{

return Encipher($input, 26 - $key);

}

$text = "rifqi";

$cipherText = Encipher($text, 3);

$plainText = Decipher($cipherText, 3);


echo $cipherText."\n";

echo $plainText;

?>

No comments:

Post a Comment

Menjadi Programmer Bukan Hanya Tentang Coding, Tapi Tentang Mempermudah Kehidupan

Semenjak menjadi seorang programmer, ada satu cara pandang yang perlahan berubah dalam diri saya. Saya mulai berpikir bahwa ilmu pemrograman...