总结¶

经验¶

• 已知密码，识别密码
• 未知密码，分析密码特性，利用暴力破解或者相应思路求解

• 加密方式判别
• 字符集判别
• 加密结果样子判别

实验吧 围在栅栏里的爱¶

-.- .. --.- .-.. .-- - ..-. -.-. --.- --. -. ... --- ---

flag格式：CTF{xxx}

2017 SECCON Vigenere3d¶

# Vigenere3d.py
import sys
def _l(idx, s):
return s[idx:] + s[:idx]
def main(p, k1, k2):
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_{}"
t = [[_l((i+j) % len(s), s) for j in range(len(s))] for i in range(len(s))]
i1 = 0
i2 = 0
c = ""
for a in p:
c += t[s.find(a)][s.find(k1[i1])][s.find(k2[i2])]
i1 = (i1 + 1) % len(k1)
i2 = (i2 + 1) % len(k2)
return c
print main(sys.argv[1], sys.argv[2], sys.argv[2][::-1])

\$ python Vigenere3d.py SECCON{**************************} **************
POR4dnyTLHBfwbxAAZhe}}ocZR3Cxcftw9


t[i][j]=s[i+j:]+s[:i+j] \\ t[i][k]=s[i+k:]+s[:i+k]

$t[i][j][k]$$t[i][j]$ 中的第 k 个字符，$t[i][k][j]$$t[i][k]$ 中的第 j 个字符。无论是 $i+j+k$ 是否超过 len(s) 两者都始终保持一致，即 $t[i][j][k]=t[i][k][j]$

def get_key(plain, cipher):
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_{}"
t = [[_l((i + j) % len(s), s) for j in range(len(s))]
for i in range(len(s))]
i1 = 0
i2 = 0
key = ['*'] * 14
for i in range(len(plain)):
for i1 in range(len(s)):
for i2 in range(len(s)):
if t[s.find(plain[i])][s.find(s[i1])][s.find(s[i2])] == cipher[
i]:
key[i] = s[i1]
key[13 - i] = s[i2]
return ''.join(key)


def decrypt(cipher, k1, k2):
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_{}"
t = [[_l((i + j) % len(s), s) for j in range(len(s))]
for i in range(len(s))]
i1 = 0
i2 = 0
plain = ""
for a in cipher:
for i in range(len(s)):
if t[i][s.find(k1[i1])][s.find(k2[i2])] == a:
plain += s[i]
break
i1 = (i1 + 1) % len(k1)
i2 = (i2 + 1) % len(k2)
return plain


➜  2017_seccon_vigenere3d git:(master) python exp.py
SECCON{Welc0me_to_SECCON_CTF_2017}