题目
flag="123"
key="12345"
assert(len(key) == 5)
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{_}"
w ={}
for i in range(len(letter)):
l = letter[i:]+letter[:i]
dic = {}
for j in range(len(l)):
dic[letter[j]] = l[j]
w[letter[i]] = dic
def encrypt(m,key):
x1 = len(m)//len(key)
x2 = len(m)%len(key)
key += x1*key + key[0:x2]
c = ""
print(len(m))
print(len(key))
for i in range(len(m)):
c += w[m[i]][key[i]]
return c
c = encrypt(flag,key)
print(c)
#DKQ6NFHDW33MAW9B}4UV1OB0{7G7VU8C1U3CO6V6
解密
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{_}"
w ={}
for i in range(len(letter)):
l = letter[i:]+letter[:i]
dic = {}
for j in range(len(l)):
dic[letter[j]] = l[j]
w[letter[i]] = dic
print(w)
m="DKQ6NFHDW33MAW9B}4UV1OB0{7G7VU8C1U3CO6V6"
key="AK_47"
x1 = len(m)//5
x2 = len(m)%5
key += x1*key + key[0:x2]
print(key)
c=""
for i in range(len(m)):
print("keyi:"+key[i])
print("mi:",m[i])
c += w[m[i]][key[i]]
print(c)
aa="DKQ6NFHDW33MAW9B}4UV1OB0{7G7VU8C1U3CO6V6"
for i in range(len(m)):
for j in letter:
if w[j][key[i]]==aa[i]:
print(j,end='')
#PRT