Feistival

Feistel 密码结构

Challenge:

m, n = 21, 22
def f(word, key):
    out = ""
    for i in range(len(word)):
        out += chr(ord(word[i]) ^ key)
    return out

flag = open("flag.txt", "r").read()

L, R = flag[0:len(flag)//2], flag[len(flag)//2:]
x = "".join(chr(ord(f(R, m)[i]) ^ ord(L[i])) for i in range(len(L)))
y = f(R, 0)

L, R = y, x
x = "".join(chr(ord(f(R, n)[i]) ^ ord(L[i])) for i in range(len(L)))
y = f(R, 0)

ciphertext = x + y
ct = open("cipher.txt", "w")
ct.write(ciphertext)
ct.close()

Decrypto:

# Decrypto
def f(word, key):
    out = ""
    for i in range(len(word)):
        out += chr(ord(word[i]) ^ key)  # ord()返回ascii
    return out

m, n = 21, 22
ciphertext = open("cipher.txt", "r").read()
x, y = ciphertext[0:len(ciphertext)//2], ciphertext[len(ciphertext)//2:]
R1 = f(y, 0)
L1 = ""
for i in range(len(x)):
    L1 += chr(ord(x[i]) ^ ord(f(R1, n)[i]))
R = f(L1, 0)
L = ""
for i in range(len(R1)):
    L += chr(ord(R1[i]) ^ ord(f(R, m)[i]))
flag = L + R

ct = open("ans.txt", "w")
ct.write(flag)
ct.close()
上一篇:opengl学习7 摄像机


下一篇:Node.js 学习记录 原生的方案开发API接口