source=b"flag{*********}" plaintext=bytes_to_long(source) length=plaintext.bit_length() a = getPrime(length) b = getPrime(length) n = getPrime(length) seed = 3281857254 print("seed = ",seed) for i inrange(10): seed = (a*seed+b)%n ciphertext = seed^plaintext print("a = ",a) print("b = ",b) print("n = ",n) print("c = ",ciphertext) # seed = 3281857254 # a = 540148988578728116547540370955365641360430675811 # b = 691767495086914115399769389216940791240924902423 # n = 524988838768493801533758786071154204860765947187 # c = 210504742144537844110730225465101123460260815127
解题脚本
1 2 3 4 5 6 7 8 9 10 11 12 13
PYTHON from Crypto.Util.number import* seed = 3281857254 a = 540148988578728116547540370955365641360430675811 b = 691767495086914115399769389216940791240924902423 n = 524988838768493801533758786071154204860765947187 c = 210504742144537844110730225465101123460260815127 for i inrange(10): seed = (a*seed+b)%n flag = c ^ seed print(long_to_bytes(flag))
PYTHON from Crypto.Util.number import* import gmpy2
a = 465177306335197714127135977948959896764918183621 b = 410163845909545695877894071846498185255806129841 n = 718249906296549710998813117372178964544291249457 c = 646736161393062036124787920588578845245377036935
ans = gmpy2.invert(a,n) seed = c for i inrange(10): seed = (ans*(seed - b)) % n flag = long_to_bytes(seed) print(flag)
from Crypto.Util.number import* import gmpy2 from math import * output = [330875235410894718431110656202775091085712343579, 234693776783263959790789380649992941515521805430, 510222815927277255176624160732162361050980242927, 123800185791875828119515172903572826221116611205, 691243560940009069435106080449371958830318872406, 207341909208395063698219222401985176654183050402, 322855546905894299222950360120836568655392882790, 163858819002800142966371893120381100654262121535, 132311867611529541744903332127948522496846295505, 72788827576169887542419201170791228486113534316] #全部未知,直接求a,b,m t=[] for i inrange(9): t.append(output[i+1]-output[i]) n=[] for i inrange(7): n.append(gcd ( ( t[i+1]*t[i-1] - t[i]*t[i] ) , ( t[i]*t[i+2] - t[i+1]*t[i+1] ) )) MMI = lambda A, n,s=1,t=0,N=0: (n < 2and t%N or MMI(n, A%n, t, s-A//n*t, N or n),-1)[n<1] #逆元计算 #print(m) for m in n: m=abs(m) if m==1: continue a = (t[3] * MMI(t[2],m)) % m b = (output[2] - a * output[1]) % m plaintext=(MMI(a,m) * (output[0] - b)) % m print(long_to_bytes(plaintext)) ''' b'\x0c' b'flag{this_is_A_text}' b'flag{this_is_A_text}' b'\x01*\xbeW\xbd\xd5\x83\x1bl\t\x84@\xf4\x87\x12\xa8_c\x88\x9f.' b"'&2\xfd|\xccI\x1aj\xf9\x8e\x14<3\x04h\xd0\xb0\xbf\xa5\xca" b'\x13\x06\xf5\x08\x18\xea\xd3\xc5(k*\x01{\x83v\xaa"\t6N\n' b'flag{this_is_A_text}' '''
from Crypto.Util.number import * from secret import FLAG p = getPrime(128) step = len(FLAG) // 3 xs = [bytes_to_long(FLAG[:step]), bytes_to_long(FLAG[step:2*step]), bytes_to_long(FLAG[2*step:])] a = getPrime(64) b = getPrime(64) c = getPrime(64) a = 18038175596386287827 b = 15503291946093443851 c = 17270168560153510007 p = 307956849617421078439840909609638388517