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

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...