encrypt
The 26 letters a, b, c, ..., y, z correspond to the integers 0, 1, 2, ..., 25
len(key_a) = m
len(key_k) = n
c[i] = (p[i] * key_a[i % m] + key_k[i % n]) % 26
p is plain text, only lowercase letters are refered to.
c is encrypted text
I have appended the flag at the end of plain text, the format of which is like 'flagis......'
Now you have the encrypted text, Good luck!
decrypt
这道题目什么都没有给我们,只给了一个加密公式,和一个输出文件.
仔细观察加密公式,发现和维吉尼亚密码很像,只不过是明文前面多了一个系数.之前的维吉尼亚爆破通过分析重合指数来逐步破解,这里也是一样.
#重合指数的应用:
import gmpy2
c=open('encrypted_message.txt','r').read()
best_index=0.065
sum=0
dic_index={
'a': 0.08167,'b': 0.01492,'c': 0.02782,'d':0.04253,'e': 0.12702,'f':0.02228,'g': 0.02015,'h':0.06094,'i':0.06966,'j':0.00153,'