0%

第三届上海市大学生网络安全大赛 Classical Writeup

分析

cipher.txt内容如下

1
Ld hcrakewcfaxr, f hofjjlhfo hlaxuc lj f krau ev hlaxuc kxfk zfj tjui xljkeclhfoor gtk dez xfj vfooud, vec kxu pejk afck, ldke iljtju. Ld hedkcfjk ke peiucd hcrakewcfaxlh foweclkxpj, pejk hofjjlhfo hlaxucj hfd gu acfhklhfoor hepatkui fdi jeoyui gr xfdi. Xezuyuc, OrmkO3vydJCoe2qyNLmcN2qlpJXnM3SxM2Xke3q9 kxur fcu foje tjtfoor yucr jlpaou ke gcufn zlkx peiucd kuhxdeoewr. Kxu kucp ldhotiuj kxu jlpaou jrjkupj tjui jldhu Wcuun fdi Cepfd klpuj, kxu uofgecfku Cudfljjfdhu hlaxucj, Zecoi Zfc LL hcrakewcfaxr jthx fj kxu Udlwpf pfhxldu fdi guredi. F btlhn gcezd veq mtpa eyuc kxu ofsr iew.

推测是移位的密码,使用WinCrypto分析得到(也可以使用quip在线分析并修复)

1
In cryptography, a classical cipher is a type of cipher that was used historically but now has fallen, for the most part, into disuse. In contrast to modern cryptographic algorithms, most classical ciphers can be practically computed and solved by hand. However, LyjtL3fvnSRlo2xvKIjrK2ximSHkJ3ZhJ2Hto3x9 they are also usually very simple to break with modern technology. The term includes the simple systems used since Greek and Roman times, the elaborate Renaissance ciphers, World War II cryptography such as the Enigma machine and beyond. A quick brown fox jump over the lazy dog.

发现该句子其实来源于英文维基百科的经典加密(Classical cipher)
发现最后一句话其实就是A quick brown fox jumps over the lazy dog.
(包含26个字母的最短句子)并去掉s
由此可以得到对照表然后恢复(当然使用WinCrypto就直接是这个字符串了)
所以可以得到原本的字符是LyjtL3fvnSRlo2xvKIjrK2ximSHkJ3ZhJ2Hto3x9

解密

直接解base64发现行不通
移位爆破
得到ZmxhZ3tjbGFzc2ljYWxfY2lwaGVyX3NvX2Vhc3l9是可以解的

爆破代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def toAlpha(c,i):
num = ord(c)
if num >= 65 and num <= 90:
num = 65 + ((num - 65) + i) % 26
elif num >= 97 and num <= 122:
num = 97 + ((num - 97) + i) % 26
return chr(num)

def encrypt(string,i):
string_new = ''
for s in string:
string_new += str(toAlpha(s,i))
print(string_new)
return string_new

def decrypt(string):
for i in range(26):
encrypt(string, -i)
encode = "LyjtL3fvnSRlo2xvKIjrK2ximSHkJ3ZhJ2Hto3x9"
decrypt(encode)

encrypt函数中加上base64解密代码即可爆破

增加代码

1
2
3
s = str(base64.b64decode(string_new))
if "flag" in s:
print(s)

参考

凯撒密码与python实现