Vigenere
Can you decrypt this message? Decrypt this message using this key "CYLAB".
import string
instr = ""
with open('cipher.txt', 'r') as a:
instr = a.readline().strip()
key = "CYLAB"
outstr = ""
offset_lower = ord('a')
offset_upper = ord('A')
lower = string.ascii_lowercase
upper = string.ascii_uppercase
dicts_l={}
for k in key:
key_loc = ord(k)-offset_upper
dicts_l[k] = {}
for l in lower:
cipher = chr((ord(l) - offset_lower + key_loc) % 26 + offset_lower)
dicts_l[k][cipher] = l
dicts_u = {}
for k in key:
key_loc = ord(k) - offset_upper
dicts_u[k] = {}
for u in upper:
dicts_u[k][chr((ord(u) - offset_upper + key_loc) % 26 + offset_upper)] = u
count=0
for c in instr:
if c.isalpha():
if c.islower():
outstr += dicts_l[key[count % len(key)]][c]
elif c.isupper():
outstr += dicts_u[key[count % len(key)]][c]
count += 1
else:
outstr += c
print(outstr)
Last updated