Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/Vigen-re-cipher/Ring/vigen-re-cipher.ring
Normal file
45
Task/Vigen-re-cipher/Ring/vigen-re-cipher.ring
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Project : Vigenère cipher
|
||||
|
||||
key = "LEMON"
|
||||
plaintext = "ATTACK AT DAWN"
|
||||
ciphertext = encrypt(plaintext, key)
|
||||
see "key = "+ key + nl
|
||||
see "plaintext = " + plaintext + nl
|
||||
see "ciphertext = " + ciphertext + nl
|
||||
see "decrypted = " + decrypt(ciphertext, key) + nl
|
||||
|
||||
|
||||
func encrypt(plain, key)
|
||||
o = ""
|
||||
k = 0
|
||||
plain = fnupper(plain)
|
||||
key = fnupper(key)
|
||||
for i = 1 to len(plain)
|
||||
n = ascii(plain[i])
|
||||
if n >= 65 and n <= 90
|
||||
o = o + char(65 + (n + ascii(key[k+1])) % 26)
|
||||
k = (k + 1) % len(key)
|
||||
ok
|
||||
next
|
||||
return o
|
||||
|
||||
func decrypt(cipher, key)
|
||||
o = ""
|
||||
k = 0
|
||||
cipher = fnupper(cipher)
|
||||
key = fnupper(key)
|
||||
for i = 1 to len(cipher)
|
||||
n = ascii(cipher[i])
|
||||
o = o + char(65 + (n + 26 - ascii(key[k+1])) % 26)
|
||||
k = (k + 1) % len(key)
|
||||
next
|
||||
return o
|
||||
|
||||
func fnupper(a)
|
||||
for aa = 1 to len(a)
|
||||
c = ascii(a[aa])
|
||||
if c >= 97 and c <= 122
|
||||
a[aa] = char(c-32)
|
||||
ok
|
||||
next
|
||||
return a
|
||||
Loading…
Add table
Add a link
Reference in a new issue