其他是一题不会啊
而且,前200就有奖?这么好?
crypto
esay_encrypt
手推一遍(字丑勿喷)
exp:
from Crypto.Util.number import *
"""from secret import flag
def f(word, key):
out = ""
for i in range(len(word)):
out += chr(ord(word[i]) ^ key)
return out
m, n = 17, 18
num = [0]*18
flag1,flag2=flag[0:len(flag)//2], flag[len(flag)//2:]
def encrypt_1(key):
L, R = key[0:len(key)//2], key[len(key)//2:]
x=''
for i in range(len(L)):
x += chr(ord(f(R, m)[i]) ^ ord(L[i]))
y = f(R, 2)
L, R = y, x
x=''
for i in range(len(L)):
x += "".join(chr(ord(f(R, n)[i]) ^ ord(L[i])) )
y = f(R, 2)
cipher = x + y
return(cipher)
c1=encrypt_1(flag1)
with open("cipher.txt", "w") as ct:
ct.write(c1 + "\n")
ct.close()
def encrypt_2(key):
l=len(key)
k = 0
for i in range(l):
num[i] = (ord(key[i]) + i) ^ (k % 3 + 1)
num[l-i-1] = ((ord(key[l-i-1]) + l) - i - 1) ^ (k % 3 +1)
k+=1
return num
c2=encrypt_2(flag2)
print("c2=",c2)"""
c1=[0x67,0x6d,0x60,0x66,0x7a,0x56,0x31,0x76,0x5e,0x0c,0x4f,0x27,0x2b,0x2e,0x2d,0x6d,0x20,0x13]
key1=""
for i in c1:
key1+=chr(i)
def f(word, key):
out = ""
for i in range(len(word)):
out += chr(ord(word[i]) ^ key)
return out
m, n = 17, 18
def xor(a1,a2):
out=""
for i in range(len(a1)):
out+=chr(ord(a1[i])^ord(a2[i]))
return out
def dec_1(key):
x2, y2 = key[0:len(key) // 2], key[len(key) // 2:]
R2=f(y2,2)
L2=f(R2,n)
L2=xor(L2,x2)
R1=f(L2,2)
L1=f(R2,m)
L1=xor(L1,R1)
print(L1+R1,end="")
dec_1(key1)
c2= [119, 107, 102, 97, 58, 114, 122, 124, 108, 122, 72, 45, 49, 48, 44, 49, 51, 141]
num = [0]*18
def dec_2(key):
l=len(key)
k=l-1
for i in range(l-1,l//2-1,-1):
num[i] = (key[i] ^ (k % 3 + 1)) - i
num[l-i-1]=(key[l-i-1]^(k%3+1))-l+i+1
k = k - 1
return num
c2=dec_2(c2)
for i in c2:
print(chr(i),end="")
#flag{W0w_y0U_FiND_the_4nswer@#$%!!!}
标签:esay,encrypt,len,range,num,key,挑战赛,ord,out
From: https://www.cnblogs.com/naby/p/18188724