90) { $rand += 6; } $codeword .= chr($rand); } return $codeword; } function getLetterValue($char) { return ord($char) - 33; } function getNumberValue($nr) { return chr((($nr + 94) % 94) + 33); } function encodeChar($char, $offset) { return getNumberValue(getLetterValue($char) + getLetterValue($offset)); } function decodeChar($char, $offset) { return getNumberValue(getLetterValue($char) - getLetterValue($offset)); } function encode($codeword, $message) { $encrypted = ""; for ($i = 0; $i < strlen($message); $i++) { $encrypted .= encodeChar(substr($message, $i, 1), substr($codeword, $i % strlen($codeword), 1)); } return $encrypted; } function hideCodeword($codeword, $message) { $len = strlen($codeword); $hidden = ""; for ($i = 0; $i < $len; $i++) { $hidden .= substr($message, $i, 1); $hidden .= substr($codeword, $i, 1); } $hidden .= substr($message, $len, strlen($message) - $len - 1); $hidden .= chr(64 + $len); $hidden .= substr($message, -1); return $hidden; } function encrypt($message) { $cw = generateCodeword(rand(7, 14)); return hideCodeword($cw, encode($cw, $message)); } function decrypt($code) { $len = ord(substr($code, -2, 1)) - 64; $code = substr($code, 0, -2) . substr($code, -1); $codedMessage = ""; $codeword = ""; for ($i = 0; $i < (2 * $len); $i += 2) { $codedMessage .= substr($code, $i, 1); $codeword .= substr($code, $i + 1, 1); } $codedMessage .= substr($code, 2 * $len); $decrypted = ""; for ($i = 0; $i < strlen($codedMessage); $i++) { $decrypted .= decodeChar(substr($codedMessage, $i, 1), substr($codeword, $i % strlen($codeword), 1)); } return $decrypted; } ?> Encryption/Decryption tool
Encryption/Decryption tool
Coderen: Decoderen: