new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
19
Task/Caesar_cipher/PHP/caesar_cipher.php
Normal file
19
Task/Caesar_cipher/PHP/caesar_cipher.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";
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue