攻防世界-Crypto萌新-Easy_Crypto(异或加密)-2017高校网络信息安全运维挑战赛

压缩包里一个密文,一个加密算法:
 

get buf unsign s[256]

get buf t[256]

we have key:hello world

we have flag:????????????????????????????????


for i:0 to 256
    
set s[i]:i

for i:0 to 256
    set t[i]:key[(i)mod(key.lenth)]

for i:0 to 256
    set j:(j+s[i]+t[i])mod(256)
        swap:s[i],s[j]

for m:0 to 37
    set i:(i + 1)mod(256)
    set j:(j + S[i])mod(256)
    swap:s[i],s[j]
    set x:(s[i] + (s[j]mod(256))mod(256))
    set flag[m]:flag[m]^s[x]

fprint flagx to file




中间有的地方i、j没有给出值,统统初始化为0即可,解密脚本:

# -*- coding: utf-8 -*-
f = open('enc.txt','r',encoding='ISO-8859-1')
c = f.read()
t = []
key = 'hello world'
ch = ''
j = 0 #初始化
s = list(range(256)) #创建有序列表
for i in range(256):
    j = (j + s[i] + ord(key[i % len(key)])) % 256
    s[i],s[j] = s[j],s[i]
i = 0 #初始化
j = 0 #初始化
for r in c:
    i = (i + 1)  % 256
    j = (j + s[i])  % 256
    s[i], s[j] = s[j], s[i]
    x = (s[i] + (s[j] % 256)) % 256
    ch += chr(ord(r) ^ s[x])
print(ch)

 

你可能感兴趣的:(攻防世界)