2018 NSEC crypto leak writeup

1.题目分析

题目可以在此处下载。下载并解压后会得到一个加密python脚本和一个加密后的wav文件。
这里写图片描述
题目描述

A recent transcript suspected to contain incriminating conversations between the officials in charge of the Mars colonization plan has leaked but is encrypted with the latest top-secret encryption algorithm: RC8! You’ve recovered the source code to their new encryption algorithm, but the key and seed value are missing. Find a weakness in the scheme and recover the transcript.

大概意思就是说希望我们在没有key和seed的情况下去解密文件。为此,我们先来看看RC8_Encrypt.py中的代码了解其是如何进行加密的。

#!/usr/bin/env python3
import sys

def rc8(state, key, n):
    '''
    Top Secret RC8 Stream Cipher
    '''
    while (n > 0):
        yield state & 0xff
        for _ in range(8):
            c, s = key, state
            b = 0
            while c:
                b ^= c & 1 * s & 1
                c >>= 1 ; s >>= 1
            state = state >> 1 | b << 63
        n -= 1

def main():
    seed, key = ?, ? # Missing

    with open(sys.argv[1], 'rb') as fin:
        data = bytearray(fin.read())

    for i,x in enumerate(rc8(seed, key, len(data))):
        data[i] ^= x

    with open(sys.argv[1] + '.enc', 'wb') as fout:
        fout.write(data)

if __name__ == "__main__":
    main()

我们可以很容易看出这是一种流加密,密钥流生成函数是rc8(),也很容易看出密钥流每次取得是state的最低八位,下面主要分析一下state是如何变化的,变化的代码如下

for _ in range(8):
            c, s = key, state
            b = 0
            while c:
                b ^= c & 1 * s & 1
                c >>= 1 ; s >>= 1
            state = state >> 1 | b << 63

c=c0c1cn1 c = c 0 c 1 ⋯ c n − 1 s=s0s1sn1 s = s 0 s 1 ⋯ s n − 1 分别是c和s的二进制表示,根据对上面代码的分析我们不难得到下面式子:
b=(c0 b = ( c 0 & s0) s 0 ) ^ (c1 ( c 1 & s1) s 1 ) ^ ^ <

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值