whaleCTF-30days-密码学【第二期】-培根的愤怒-writeup

题目:

我这么精辟的密码为什么不能入大流!?今天我将于RSA和AES并肩行走哈哈!
答案格式whaleCTF{xxxx},xxx为解密内容

打开压缩包,发现有一个RSA.txt,一个bacon.docx,打开bacon.docx发现需要密码,考虑从RSA.txt下手:

打开RSA发现熟悉的内容:

e=65537
d=1764836219594882187843234147880131121771889292946179667759840214035309185449143902593959870508966515039587677582858798736388141160230363016947313129036070636861863062274037967590147497869727514848002031984248933650359661708519627935253774817417127743601824768881728368241731993209298718491920343736819541250453047663176408059126018948310585981572755980858657248028686387003137268571851611561132111915826966459925826207250507344818626890563618085762697380861169320463283242104640942973559724123517932751088369262105675358771667412984908724301206109885898719604228198681639407843267405644475201507847567204728939638145
n=20136154478340841564185591286493759284046711105817161714132424809754884764411654586403263933416806841251646522588408268242804597356897162437617698561566323350977701864946661957164954137863567573223103964162904311393388083111290190806533189451439119243111558126427895555267825494247529615913123880132301928087149633155689369834486059262333901654707896271411583403909233265498204545037789075685761561868755049395178667956582626590509735929833007473306687014665509839236897398732632601168593411571576144377460423772237026851061695263350092752542823717948134419111797673566903960499882658784242463197583753031104747152067
c=22F4ECF53A876B17DA59DFA44235B8AB08F93D337D79427B13BC3036933FC850E0697926C625B6DCD5D21955D2BB43CB5348197FA6F79C74424D13B0157914E81BF462FF96FABF9E152284732C12148C4FAAF3FD04BDE5E97DCAE7DD41046BD7340FE024767003DC79B5CABD50738886F54D8FFDC2B81AD57EDEF35AD54D58B7BD9A15380BF5BB88A82EEF4148C4EE27589122C9FC9E9BEE94B235FD8FA77C431290A56BC13269FD1171AF8A382A3A6919C7F2B1CC8758DB0AE9982BB02EB37499F211D215C9C62CFE379ED63EC248939458D7498E224F6FA13F816E54504986B8CC391160CB527D4D54DB7B23CC7C29420B996D168E5C6990DBA72E9FA93C37

e代表公钥,d代表私钥,n代表模数,c代表密文。

使用工具直接进行解明文即可:

whaleCTF-30days-密码学【第二期】-培根的愤怒-writeup_第1张图片

得到whaleCTFCR1pt0,提交flag发现不对,使用这个明文去解密bacon.docx文件,成功解密,打开文档,发现是空白,

 whaleCTF-30days-密码学【第二期】-培根的愤怒-writeup_第2张图片

ctrl+a 全选发现有内容,将字体更改颜色,发现内容:

whaleCTF-30days-密码学【第二期】-培根的愤怒-writeup_第3张图片

我们发现有斜体和正体两种字符,再根据文档的名称,想到培根密码,将正体用a替代,斜体用b替换,得到培根密码:

aaaab aaaaa aaaba abbba abbab abaaa baaba aaaaa abbab aabba baaab bbaaa

使用python脚本直接解密,这里提供一下培根密码解密脚本,支持两种培根密码表:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import re

alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

first_cipher = ["aaaaa","aaaab","aaaba","aaabb","aabaa","aabab","aabba","aabbb","abaaa","abaab","ababa","ababb","abbaa","abbab","abbba","abbbb","baaaa","baaab","baaba","baabb","babaa","babab","babba","babbb","bbaaa","bbaab"]

second_cipher = ["aaaaa","aaaab","aaaba","aaabb","aabaa","aabab","aabba","aabbb","abaaa","abaaa","abaab","ababa","ababb","abbaa","abbab","abbba","abbbb","baaaa","baaab","baaba","baabb","baabb","babaa","babab","babba","babbb"]

def encode():
    string = raw_input("please input string to encode:\n")
    e_string1 = ""
    e_string2 = ""
    for index in string:
        for i in range(0,26):
            if index == alphabet[i]:
                e_string1 += first_cipher[i]
                e_string2 += second_cipher[i]
                break
    print "first encode method result is:\n"+e_string1
    print "second encode method result is:\n"+e_string2
    return


def decode():
    e_string = raw_input("please input string to decode:\n")
    e_array = re.findall(".{5}",e_string)
    d_string1 = ""
    d_string2 = ""
    for index in e_array:
        for i in range(0,26):
            if index == first_cipher[i]:
                d_string1 += alphabet[i]
            if index == second_cipher[i]:
                d_string2 += alphabet[i]
    print "first decode method result is:\n"+d_string1
    print "second decode method result is:\n"+d_string2
    return


if __name__ == '__main__':
    while True:
        print "\t*******Bacon Encode_Decode System*******"
        print "input should be lowercase,cipher just include a b"
        print "1.encode\n2.decode\n3.exit"
        s_number = raw_input("please input number to choose\n")
        if s_number == "1":
            encode()
            raw_input()
        elif s_number == "2":
            decode()
            raw_input()
        elif s_number == "3":
            break
        else:
            continue

 运行得到flag:

whaleCTF-30days-密码学【第二期】-培根的愤怒-writeup_第4张图片

 

 

你可能感兴趣的:(CTF,密码学)