Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Vigen-re-cipher/Nim/vigen-re-cipher.nim
Normal file
24
Task/Vigen-re-cipher/Nim/vigen-re-cipher.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import strutils
|
||||
|
||||
proc encrypt(msg, key: string): string =
|
||||
var pos = 0
|
||||
for c in msg:
|
||||
if c in Letters:
|
||||
result.add chr(((ord(key[pos]) + ord(c.toUpperAscii)) mod 26) + ord('A'))
|
||||
pos = (pos + 1) mod key.len
|
||||
|
||||
proc decrypt(msg, key: string): string =
|
||||
var pos = 0
|
||||
for c in msg:
|
||||
result.add chr(((26 + ord(c) - ord(key[pos])) mod 26) + ord('A'))
|
||||
pos = (pos + 1) mod key.len
|
||||
|
||||
const text = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
|
||||
const key = "VIGENERECIPHER"
|
||||
|
||||
let encr = encrypt(text, key)
|
||||
let decr = decrypt(encr, key)
|
||||
|
||||
echo text
|
||||
echo encr
|
||||
echo decr
|
||||
Loading…
Add table
Add a link
Reference in a new issue