112b. Encrypt and decrypt text using substitution cipher method.
Invoke function using 3 arguments.
1st arg (string) ... Input pain/cipher text. Its can contain only English alphabet [a..z], no punctuation.
2nd arg (number) ... The key text. Contain each of a lower case English alphabet [a..z]{26}.
3rd arg (number) ... Direction of encrypt/decrypt. 1 for encryption and 0 for decryption.
While Affine Cipher is a very-hard-to-understand, nearly-mind-explosive-on-implement; Substitution Cipher provide a much-easier-to-learn, no-queer-coding-require. Above of all, substitution cipher had fully cover on what affine cipher had already done!
Nevertheless, I love affine cipher the most! Because its remind me how wonderful mathematics is.
124b -> 112b williammalo
You can make it smaller.
original:
function(t,k,d){for(var i=0,o="";i<t.length;i++)o+=d?k[t.charCodeAt(i)-97]:String.fromCharCode(k.indexOf(t[i])+97);return o}
smaller version:
function(t,k,d,i,o){o="";for(i in t)o+=d?k[t.charCodeAt(i)-97]:String.fromCharCode(k.indexOf(t[i])+97);return o}