Vigenère cipher: Difference between revisions

Content added Content deleted
(Added Quackery.)
(Updated to work with Nim 1.4: added missing parameter types; replaced "toUpper" with "toUpperAscii". Also, some other modifications.)
Line 1,947:
<lang nim>import strutils
 
proc encrypt(msg, key: string): string =
proc isAlpha(c): bool = c in 'a'..'z' or c in 'A'..'Z'
 
proc encrypt(msg, key): string =
result = ""
var pos = 0
for c in msg:
if isAlpha c in Letters:
result.add chr(((ord(key[pos]) + ord(toUpper c.toUpperAscii)) mod 26) + ord('A'))
pos = (pos + 1) mod key.len
 
proc decrypt(msg, key: string): string =
result = ""
var pos = 0
for c in msg:
Line 1,973 ⟶ 1,969:
echo encr
echo decr</lang>
 
{{out}}
<pre>Beware the Jabberwock, my son! The jaws that bite, the claws that catch!