Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Caesar-cipher/PHP/caesar-cipher-1.php
Normal file
19
Task/Caesar-cipher/PHP/caesar-cipher-1.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
function caesarEncode( $message, $key ){
|
||||
$plaintext = strtolower( $message );
|
||||
$ciphertext = "";
|
||||
$ascii_a = ord( 'a' );
|
||||
$ascii_z = ord( 'z' );
|
||||
while( strlen( $plaintext ) ){
|
||||
$char = ord( $plaintext );
|
||||
if( $char >= $ascii_a && $char <= $ascii_z ){
|
||||
$char = ( ( $key + $char - $ascii_a ) % 26 ) + $ascii_a;
|
||||
}
|
||||
$plaintext = substr( $plaintext, 1 );
|
||||
$ciphertext .= chr( $char );
|
||||
}
|
||||
return $ciphertext;
|
||||
}
|
||||
|
||||
echo caesarEncode( "The quick brown fox Jumped over the lazy Dog", 12 ), "\n";
|
||||
?>
|
||||
9
Task/Caesar-cipher/PHP/caesar-cipher-2.php
Normal file
9
Task/Caesar-cipher/PHP/caesar-cipher-2.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
function caesarEncode($message, $key) {
|
||||
$from = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$to = substr($from, $key) . substr($from, 0, $key);
|
||||
return strtr($message, $from, $to);
|
||||
}
|
||||
|
||||
echo caesarEncode('THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG', 12), PHP_EOL;
|
||||
Loading…
Add table
Add a link
Reference in a new issue