BUUCTF(传统知识+古典密码)

先下载文件,发现有两个东西

然后再看题目:传统知识加古典密码

第一个文件,信中的不同年份目前不知道是什么密码,应该属于传统知识了,然后对照表格,看各个年份分别对应的数字,发现分别是这几个数字: 28  30  23 08  17  10  16  30

然后再看到信的背面还有一个+甲子,一甲子=60年

然后把60加到上面一段数字中可以得到数字串:88  90  83  68  77  70  76  90

再然后把这些数字对应ASCII表,可以得到一串字母:XZSDMFLZ

ASCII对应表如下:

传统知识阶段就结束了,然后就是古典密码阶段:

古典密码编码方法归根结底主要有两种,即置换和代换。

把明文中的字母重新排列,字母本身不变,但其位置改变了,这样编成的密码称为置换密码。最简单的置换密码是把明文中的字母顺序倒过来,然后截成固定长度的字母组作为密文。

代换密码则是将明文中的字符替代成其他字符。

古典密码主要有栅栏,凯撒,棋盘,摩丝等等,最常见的应该是栅栏和凯撒

然后把一串字母分别用栅栏和凯撒解密,先是栅栏密码,key=2,解密得到XMZFSLDZ,然后再用凯撒密码,key=5,解密得到SHUANGYU

这就是flag{SHUANGYU},附上解密工具网站:http://ctf.ssleye.com/?tdsourcetag=s_pcqq_aiomsg

至于为什么先是栅栏再是凯撒,是因为我先用凯撒解不出来。。。后来才换了栅栏。为什么key的值直接能给出2和5,因为借鉴的。。。

然后还有一种方法:都用python脚本解

话不多说,先上代码

首先是栅栏密码解密:

def zhalan(e):
    elen = len(e)
    field = []
    for i in range(2, elen):
        if (elen % i == 0):
            field.append(i)

    for f in field:
        b = elen // f
        result = {x: '' for x in range(b)}
        for i in range(elen):
            a = i % b;
            result.update({a: result[a] + e[i]})
        d = ''
        for i in range(b):
            d = d + result[i]
        print(d)
        d.lower()


if __name__ == '__main__':
    e = 'XZSDMFLZ'
    zhalan(e)

然后就能解出两串字母,然后再用python脚本:

def casearDecrypt(ciphertext, source_char, destination_char, list_all):
    if list_all == True:
        for offset in range(1, 27):
            convertChar(offset)
    else:
        offset = ord(destination_char) - ord(source_char)
        convertChar(offset)


def convertChar(offset):
    chars = "abcdefghijklmnopqrstuvwxyz"
    for char in ciphertext:

        is_upper_flag = 0
        if char.isupper():
            char = char.lower()
            is_upper_flag = 1

        if char not in chars:
            outputChar(is_upper_flag, char)
            continue

        tempchar_ascii = ord(char) + offset
        tempchar = chr(tempchar_ascii)
        if tempchar not in chars:
            if offset < 0:
                tempchar_ascii += len(chars)
            else:
                tempchar_ascii -= len(chars)
        tempchar = chr(tempchar_ascii)
        outputChar(is_upper_flag, tempchar)
    print("")


def outputChar(is_upper_flag, char):
    if is_upper_flag == 1:
        print(char.upper(), end="")
    else:
        print(char, end="")


ciphertext = input("Please input ciphertext:\n")
while True:
    operation = input("List all results?y/n:")
    if operation == 'y' or operation == 'Y':
        casearDecrypt(ciphertext, '', '', True)
        break
    elif operation == 'n' or operation == 'N':
        des_char = input("Please input destination_char:\n")
        sors_char = input("Please input source_char:\n")
        casearDecrypt(ciphertext, sors_char, des_char, False)
        break
    else:
        print("Input error! Please input y/n:")
把上一个脚本得到的两串字母分别带入下面一个脚本中就可以得到flag了。

 

 

 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值