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 encrypt(msg, key): string =
var pos = 0
for c in msg:
if
result.add chr(((ord(key[pos]) + ord(
pos = (pos + 1) mod key.len
proc decrypt(msg, key: string): string =
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!
|