###### tags: `writeups` # Writeup for part_des in 2019国赛 ## 0x00 Problem ``` Round n part_encode-> 0x92d915250119e12b Key map -> 0xe0be661032d5f0b676f82095e4d67623628fe6d376363183aed373a60167af537b46abc2af53d97485591f5bd94b944a3f49d94897ea1f699d1cdc291f2d9d4a5c705f2cad89e938dbacaca15e10d8aeaed90236f0be2e954a8cf0bea6112e84 ``` ## 0x01 Observation DES加密,给出了所有的(16对)子密钥和第n轮的加密结果。 DES是一个对称的加密结构,既然都有了所有的子密钥了,解密不会是问题。  DES的加解密十分对称,解密就是用子密钥倒着加密。 不过这里第n轮中的n未知,可以穷举1~16。 Summary: - 穷举n - 解密的时候子密钥要倒着 - 由于是中间结果,所以没有最后一轮的左右两半轮换和FP,所以解密的时候要注意下 ## 0x02 Exp ```python # python3 from des import * # https://github.com/soreatu/Cryptography from Utility import * from Crypto.Util.number import * m = Bytes2Block(long_to_bytes(0x92d915250119e12b)) k = long_to_bytes(0xe0be661032d5f0b676f82095e4d67623628fe6d376363183aed373a60167af537b46abc2af53d97485591f5bd94b944a3f49d94897ea1f699d1cdc291f2d9d4a5c705f2cad89e938dbacaca15e10d8aeaed90236f0be2e954a8cf0bea6112e84) subkey = [ Bytes2Block(k[i:i+6]) for i in range(0,len(k), 6)] # 子密钥48 bits(6 bytes)一组 # m的右半部是Li-1和F()异或的结果,所以需要用m的右半部作为解密的Li(Feistel网络中Li用来异或) Ri, Li = m[:32], m[32:] for n in range(16): nn = n LLi,RRi=Li,Ri while nn > 0: LLi,RRi = RRi, BlockXor(LLi, Feistel(RRi,subkey[nn-1])) nn-=1 mm = RRi+LLi mm = FP(mm) print(Block2Bytes(mm)) # b'\xbfB\x052t\x0b\x18X' # b'/\xd4\x0f5\xe8B!\xb1' # b'l\xa71?I}3{' # b'l\xc7!\x97\x08@\x1c\xe9' # b'&L\x1b\x9c\x85tT\xae' # b'5\xa3!P\n\xf4\xcb\xe2' # b'Bh\xa4~$)\x1e\xa3' # b'\xd7\xcd\x0e9\xd2\x185S' # b'\xf2\x1b ;\xf0\xdc\xa4\xdf' # b'\x93\xc0\xa4Zz\xa2\xbb\x13' # b'\xc2o\xe3\xaah\x0e\xe1f' # b')\xc1`r\xfb\xd5\xfb\x9d' # b'\xb5p^\xdb\xe9=\xb9\x88' # b'y0ur9Ood' # b't-\xcfE\xcfx\x90\xa7' # b'\x8a\x1eD\x9a0\x94\x18/' ``` 可以看到`y0ur9Ood`,即为flag ## 0x03 Reference [1] [https://ctf-wiki.github.io/ctf-wiki/crypto/blockcipher/des/#2019-ciscn-part_des](https://ctf-wiki.github.io/ctf-wiki/crypto/blockcipher/des/#2019-ciscn-part_des)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up