每天一题,只能多不能少
Feistel
题目分析
- 类似feistel
- 密钥碰撞
开始
1.题目
给出feistel.py和feistel.log
feistel.py
#!/usr/bin/python
#encoding=utf-8
import os
def strxor(a,b):
assert len(a) == len(b)
c = ''
for i in range(len(a)):
c += chr(ord(a[i])^ord(b[i]))
return c
def round(M, K):
L = M[0:27]
R = M[27:54]
new_l = R
new_r = strxor(strxor(R, L), K)
return new_l+new_r
def fez(m,K):
for i in K:
m = round(m, i)
return m
K = []
for i in range(7):
K.append(os.urandom(27))
m = open("flag.txt","rb").read()
assert len(m)<54
m += os.urandom(54-len(m))
test = os.urandom(54)
print 'test = '+test.encode("hex")
print 'fez(test,K) = '+fez(test,K).encode("hex")
print 'fez(m,K) = '+fez(m,K).encode("hex")
feistel.log
test = 1a8b7027a3766821a072a779c0879f3d6bf06dbea48e2d52a390f3b68386d48f7f45cc15388d65aca04500d17e4c105b2911625e8bc6
fez(test,K) = e704fb0de86487c7ceee1d95555cef945b5b2fee4c5454b36a8f84bebed7cd63bb86cec33f4de2aea3f5ca4f6e859d679854d8b3a6d5
fez(m,K) = 39e62fbd1a3b8b05da0eafd5471774f650079a99942d5d5153577b1cbb123d49d4d14445d96bb7235d85e77aa1290b725d2f06199a86
2.分析
就是2018年护网杯的fez。。。。。只是改了下加密的内容而已。
加密过程类似DES的feistel。
也就是
L 7 = R 0 ⨁ K 2 ⨁ K 3 ⨁ K 5 ⨁ K 6 R 7 = L 0 ⨁ R 0 ⨁ K 1 ⨁ K 3 ⨁ K 4 ⨁ K 6 ⨁ K 7 L_7=R_0 \bigoplus K_2 \bigoplus K_3 \bigoplus K_5 \bigoplus K_6\\ R_7=L_0 \bigoplus R_0 \bigoplus K_1 \bigoplus K_3 \bigop