块密码
mt19937
困难的,难逆向的,脚本小子的。
RC4
from Cryptodome.Cipher import ARC4
def encrypt(key, data):
cipher = ARC4.new(key)
return cipher.encrypt(data)
def decrypt(key, data):
cipher = ARC4.new(key)
return cipher.decrypt(data)
key = b'secretkey'
data = b'hello, world'
# 加密
encrypted_data = encrypt(key, data)
print("加密后的数据:" + str(encrypted_data))
# 解密
decrypted_data = decrypt(key, encrypted_data)
print("解密后的数据:" + str(decrypted_data, encoding='utf-8'))
lcg
这个感觉自己学的挺好的(
直接放一个\(a,b,m\)都要求的题
from Crypto.Util.number import *
from gmpy2 import *
"""
flag = b'Spirit{****************************************}'
plaintext = bytes_to_long(flag)
length = plaintext.bit_length()
a = getPrime(length)
b = getPrime(length)
n = getPrime(length)
seed = plaintext
output = []
for i in range(10):
seed = (a*seed+b)%n
output.append(seed)
print("output = ",output)
"""
ot = [9997297986272510947766344959498975323136012075787120721424325775003840341552673589487134830298427997676238039214108, 4943092972488023184271739094993470430272327679424224016751930100362045115374960494124801675393555642497051610643836, 6774612894247319645272578624765063875876643849415903973872536662648051668240882405640569448229188596797636795502471, 9334780454901460926052785252362305555845335155501888087843525321238695716687151256717815518958670595053951084051571, 2615136943375677027346821049033296095071476608523371102901038444464314877549948107134114941301290458464611872942706, 11755491858586722647182265446253701221615594136571038555321378377363341368427070357031882725576677912630050307145062, 7752070270905673490804344757589080653234375679657568428025599872155387643476306575613147681330227562712490805492345, 8402957532602451691327737154745340793606649602871190615837661809359377788072256203797817090151599031273142680590748, 2802440081918604590502596146113670094262600952020687184659605307695151120589816943051322503094363578916773414004662, 5627226318035765837286789021891141596394835871645925685252241680021740265826179768429792645576780380635014113687982]
t=[0]*10
for i in range(9):
t[i]=ot[i+1]-ot[i]
m=gcd((t[7]*t[5]-t[6]*t[6]),(t[6]*t[4]-t[5]*t[5]))
a=((ot[9]-ot[8])*invert(ot[8]-ot[7],m))%m
b=(ot[9]-a*ot[8])%m
ans=((ot[0]-b)*invert(a,m))%m
print(long_to_bytes(ans))