139b. Encrypt and decrypt text using affine cipher method.
Invoke function using 4 arguments.
1st arg (string) ... Input pain/cipher text. Its can contain only English alphabet [a..z], no punctuation.
2nd arg (number) ... The multiplication number. Only [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25] are valid.
3rd arg (number) ... The key number. Range [0..25].
4th arg (number) ... Direction of encrypt/decrypt. 1 for encryption and 0 for decryption.
By studying @wrayal's Vigenère Cipher. I decide to implement the popular well-known Caesar cipher again.
But then I realized that Caesar cipher is just one special case from Vigenère cipher. That's mean I done nothing new! So I rewrite this function in Affine cipher. Which still can be use as the Caesar cipher by setting the 2nd arg = 1, e.g. function("texthere", 1, 4, 1)
.
i and o are leaking the global scope.