[Writeup] BUGKU CTF Crypto 托马斯.杰斐逊

[复制链接]
查看13474 | 回复0 | 2017-5-28 21:54:01 | 显示全部楼层 |阅读模式
以下解题方法参照王心慰的博客
首先根据密钥的值对加密表进行重新组合,得到加密表
[mw_shl_code=python,true]KPBELNACZDTRXMJQOYHGVSFUWI
IHFRLABEUOTSGJVDKCPMNZQWXY
ZWAXJGDLUBVIQHKYPNTCRMOSFE
BDMAIZVRNSJUWFHTEQGYXPLOCK
AMKGHIWPNYCJBFZDRUSLOQXVET
RPLNDVHGFCUKTEBSXQYIZMJWAO
QWATDSRFHENYVUBMCOIKZGJXPL
GWTHSPYBXIZULVKMRAFDCEONJQ
NOZUTWDCVRJLXKISEFAPMYGHBQ
XPHKZGJTDSENYVUBMLAOIRFCQW
WABMCXPLTDSRJQZGOIKFHENYVU
BMCSRFHLTDENQWAOXPYVUIKZGJ
XPLTDAOIKFZGHENYSRUBMCQWVJ
TDSWAYXPLVUBOIKZGJRFHENMCQ[/mw_shl_code]
然后根据密文的值,对加密表的每一行的首字母转到对应的值
[mw_shl_code=python,true]HGVSFUWIKPBELNACZDTRXMJQOY
CPMNZQWXYIHFRLABEUOTSGJVDK
BVIQHKYPNTCRMOSFEZWAXJGDLU
TEQGYXPLOCKBDMAIZVRNSJUWFH
SLOQXVETAMKGHIWPNYCJBFZDRU
XQYIZMJWAORPLNDVHGFCUKTEBS
WATDSRFHENYVUBMCOIKZGJXPLQ
CEONJQGWTHSPYBXIZULVKMRAFD
RJLXKISEFAPMYGHBQNOZUTWDCV
QWXPHKZGJTDSENYVUBMLAOIRFC
GOIKFHENYVUWABMCXPLTDSRJQZ
LTDENQWAOXPYVUIKZGJBMCSRFH
ENYSRUBMCQWVJXPLTDAOIKFZGH
SWAYXPLVUBOIKZGJRFHENMCQTD[/mw_shl_code]
最后遍历每一列,选择最可能的明文
[mw_shl_code=python,true]HCBTSXWCRQGLES
GPVELQAEJWOTNW
VMIQOYTOLXIDYA
SNQGQIDNXPKESY
FZHYXZSJKHFNRX
UQKXVMRQIKHQUP
WWYPEJFGSZEWBL
IXPLTWHWEGNAMV
KYNOAAETFJYOCU
PITCMONHATVXQB
BHCKKRYSPDUPWO
EFRBGPVPMSWYVI
LRMDHLUYYEAVJK
NLOMINBBGNBUXZ
AASAWDMXHYMIPG
CBFIPVCIBVCKLJ
ZEEZNHOZQUXZTR
DUZVYGIUNBPGDF
TOWRCFKLOMLJAH
RTANJCZVZLTBOE
XSXSBUGKUADMIN
MGJJFKJMTOSCKM
JJGUZTXRWIRSFC
QVDWDEPADRJRZQ
ODLFRBLFCFQFGT
YKUHUSQDVCZHHD[/mw_shl_code]
附上本题的Python代码
[mw_shl_code=python,true]table = '''ZWAXJGDLUBVIQHKYPNTCRMOSFE
KPBELNACZDTRXMJQOYHGVSFUWI
BDMAIZVRNSJUWFHTEQGYXPLOCK
RPLNDVHGFCUKTEBSXQYIZMJWAO
IHFRLABEUOTSGJVDKCPMNZQWXY
AMKGHIWPNYCJBFZDRUSLOQXVET
GWTHSPYBXIZULVKMRAFDCEONJQ
NOZUTWDCVRJLXKISEFAPMYGHBQ
QWATDSRFHENYVUBMCOIKZGJXPL
WABMCXPLTDSRJQZGOIKFHENYVU
XPLTDAOIKFZGHENYSRUBMCQWVJ
TDSWAYXPLVUBOIKZGJRFHENMCQ
BMCSRFHLTDENQWAOXPYVUIKZGJ
XPHKZGJTDSENYVUBMLAOIRFCQW'''
key = (2, 5, 1, 3, 6, 4, 9, 7, 8, 14, 10, 13, 11, 12)
cipher = 'HCBTSXWCRQGLES'
table = table.split()
table = [table[key[x] - 1] for x in range(14)]
key = [table[x].index(cipher[x]) for x in range(len(cipher))]
for i in range(len(table)):
    table = table[key:] + table[:key]
for i in range(26):
    s = ''
    for j in range(len(table)):
        s += table[j]
    print s
[/mw_shl_code]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

匿名
p1ain 该用户已被删除