<?php
function monoAlphabeticCipher($key, $alphabet, $text){
$cipherText = '';
if ( strlen($key) != strlen($alphabet) ) { return false; }
$text = preg_replace('/[0-9]+/', '', $text);
for( $i = 0; $i < strlen($text); $i++ ){
$index = strripos( $alphabet, $text[$i] );
if( $text[$i] == " " ){ $cipherText .= " "; }
else{ $cipherText .= ( ctype_upper($text[$i]) ? strtoupper($key[$index]) : $key[$index] ); }
}
return $cipherText;
}
function maEncrypt($key, $alphabet, $text){
return monoAlphabeticCipher($key, $alphabet, $text);
}
function maDecrypt($key, $alphabet, $text){
return monoAlphabeticCipher($alphabet, $key, $text);
}
?>