# The exuberant new year of 2024 will bring us joy and excitement! p, q = choice(Goldbach_christian) Exuberant_p = EllipticCurve(GF(Happy_2024), [0, p]) Exuberant_q = EllipticCurve(GF(Haqqy_2024), [0, q])
# Happy New Year! m = bytes_to_long(FLAG) withopen(r"./output.txt", "w") as f: gift1 = bytes_to_long(str(Exuberant_p.order() + q).encode()) * bytes_to_long(str(Haqqy_2024 + p).encode()) gift2 = bytes_to_long(str(Happy_2024 + q).encode()) * bytes_to_long(str(Exuberant_q.order() + p).encode()) print(f"I'll give the gifts to U: {Hanny_2024, gift1, gift2}", file = f) red_envelope1 = pow(Happy_2024 * m + Exuberant_p.order(), Haqqy_2024, Hanny_2024) red_envelope2 = pow(Haqqy_2024 * m + Exuberant_q.order(), Happy_2024, Hanny_2024) print(f"OKOK ~ I'll give U both my red envelopes: {(red_envelope1 + red_envelope2) % Hanny_2024}", file = f)
output.txt
I'll give the gifts to U: (20243063012381093065881715376803640816923818203625911640694784993789286636611180835921608390045413835542916314861539938722171842014382670606414163394994894668365164929867556130798284960121925034107155666591563718174618437343159515015854655008175217672889911863891053034708651435516540210570245991063171289, 3082830559038877744539857448969808147340468463825357858541058129026110543191536241000397185264316057842094866363953733054989122356139453391356731191975829726832037786724893103057593038097144042673463810432983923372914638559633536471618619482302004617729891895118724873404754109722821248796445568519005866543646123446178955716385193501431092935028347031054773643129268914254426313530748324498727786408429432156630438289014574042635727761302151785956285737839574363413926555001728577343808599432210101775474025849266347224644582573221902585346919924996022499981173366240328668308502429507808470604746535923016683822196192993568289713072203814997890729262294909812821367061856088587537284075245689333865060423210347243013777511472403383304, 3082830559038877744539857448969808147340468463825357858541058129026110543191536241000397185264316057842094866363953733054989122356139453391356731191975829726832037786724893103057593038216217536027471947135543545371933118755272502325512823354293788008534797452079854008261955881875509964629925233416040952762759456529527642367686423321679563388067512673864367064259939501631392224619750617648481056541218717491489589148264984800793218746131598354744063462469714933567095917446196156778081743234319680672351161560960057307138485005738193883799762282567263840999618884631103691058355449154243356632772447934686630333029322247571260185386757991734700408212263554584499979733547418238195693215881963434496586637612459533424028727466150670988) OKOK ~ I'll give U both my red envelopes: 2053306399329493484171909216754446971778876338572305861281393386450367892503612914088507585084261917515228499040036138151202134583664706045917520505194094450066544241663702222706889993979023385508314787933724825993887808366549319278298208023774104687051338473854159671013079568527042769852891874689463806
New_Year = 2024 Goldbach_christian = [(p, New_Year - p) for p in sieve_base if p <= New_Year // 2and isPrime(New_Year - p)]
根据上述代码可知,列表 Goldbach_christian 空间是很小的,因此枚举即可
至此已经可以求出两个素数了,下面先给出一部分代码。
from Crypto.Util.number import *
New_Year = 2024 Goldbach_christian = [(p, New_Year - p) for p in sieve_base if p <= New_Year // 2and isPrime(New_Year - p)]
deffactor(nh, ng, a, b, f = lambda x: bytes_to_long(str(x).encode())): nh_p = None deftest_digits(ps, qs): nonlocal nh_p if nh_p isnotNone: returnFalse p = sum([pi * 10 ** i for i, pi inenumerate(ps)]) p_with_a = p + a new_ps = [int(i) for i instr(p_with_a).zfill(len(ps))[::-1]][:len(ps)] pp = sum([(48 + pi) << (i * 8) for i, pi inenumerate(new_ps)]) q = sum([pi * 10 ** i for i, pi inenumerate(qs)]) q_with_b = q + b new_qs = [int(i) for i instr(q_with_b).zfill(len(qs))[::-1]][:len(qs)] qq = sum([(48 + qi) << (i * 8) for i, qi inenumerate(new_qs)]) if p != 0and p != 1and nh % p == 0: nh_p = p returnFalse m1 = 10 ** len(ps) m2 = 1 << (len(qs) * 8) return (p * q) % m1 == nh % m1 and (pp * qq) % m2 == ng % m2
stack = [([], [])] while stack: ps, qs = stack.pop() stack += [(ps + [i], qs + [j]) for i inrange(10) for j inrange(10) if test_digits(ps + [i], qs + [j])]
ng_p = f(nh_p + a) assert ng % ng_p == 0 return nh_p, nh // nh_p
New_Year = 2024 Goldbach_christian = [(p, New_Year - p) for p in sieve_base if p <= New_Year and isPrime(New_Year - p)] defget_factors(n, nn, ABlist): Hp, Hq, p, q = None, None, None, None for a, b in ABlist: try: Hp, Hq = factor(n, nn, a + 1, b) print(Hp, Hq, a, b) p, q = a, b break except: pass return Hp, Hq, p, q pH, qH, p, q = get_factors(n, g1, Goldbach_christian) if pH isNoneor qH isNone: pH, qH, p, q = get_factors(n, g2, Goldbach_christian)
New_Year = 2024 Goldbach_christian = [(p, New_Year - p) for p in sieve_base if p <= New_Year // 2and isPrime(New_Year - p)]
deffactor(nh, ng, a, b, f = lambda x: bytes_to_long(str(x).encode())): nh_p = None deftest_digits(ps, qs): nonlocal nh_p if nh_p isnotNone: returnFalse p = sum([pi * 10 ** i for i, pi inenumerate(ps)]) p_with_a = p + a new_ps = [int(i) for i instr(p_with_a).zfill(len(ps))[::-1]][:len(ps)] pp = sum([(48 + pi) << (i * 8) for i, pi inenumerate(new_ps)]) q = sum([pi * 10 ** i for i, pi inenumerate(qs)]) q_with_b = q + b new_qs = [int(i) for i instr(q_with_b).zfill(len(qs))[::-1]][:len(qs)] qq = sum([(48 + qi) << (i * 8) for i, qi inenumerate(new_qs)]) if p != 0and p != 1and nh % p == 0: nh_p = p returnFalse m1 = 10 ** len(ps) m2 = 1 << (len(qs) * 8) return (p * q) % m1 == nh % m1 and (pp * qq) % m2 == ng % m2
stack = [([], [])] while stack: ps, qs = stack.pop() stack += [(ps + [i], qs + [j]) for i inrange(10) for j inrange(10) if test_digits(ps + [i], qs + [j])]
ng_p = f(nh_p + a) assert ng % ng_p == 0 return nh_p, nh // nh_p
New_Year = 2024 Goldbach_christian = [(p, New_Year - p) for p in sieve_base if p <= New_Year and isPrime(New_Year - p)] defget_factors(n, nn, ABlist): Hp, Hq, p, q = None, None, None, None for a, b in ABlist: try: Hp, Hq = factor(n, nn, a + 1, b) print(Hp, Hq, a, b) p, q = a, b break except: pass return Hp, Hq, p, q pH, qH, p, q = get_factors(n, g1, Goldbach_christian) if pH isNoneor qH isNone: pH, qH, p, q = get_factors(n, g2, Goldbach_christian)
unit = b"\x00" * 15 + b"\x01" A = bytes_to_long(unit * 8)
unit = b"\x00" * 16 B = bytes_to_long(b"\01" + unit * 8)
ap = pow(g, A * (p - 1), p ** 2) - 1 bp = pow(g, B * (p - 1), p ** 2) - 1
assertint(ap) % p == 0 assertint(bp) % p == 0
a, b = int(ap) // p, int(bp) // p C = (b * inverse(a, p)) % p S = int(pow(int(secret), p - 1, p ** 2)) - 1 assertint(S) % p == 0 S = ((int(S) // p) * inverse(a, p)) % p
M = matrix([[1/2**(768 - 128), 0, C], [0, 2**128, S], [0, 0, p]]) ML = M.LLL() print(ML) for v in ML: the_flag = abs((v * (2 ** (768 - 128)))[0]) print(long_to_bytes(int(the_flag)))
defgetSec(h1, h2, bits): mat = matrix(ZZ, [[h1, 1, 0], [h2, 0, 1]]) mat = mat.LLL() t, a2, a1 = mat[0] a2, a1 = abs(a2), abs(a1) pre_p = h1 // a1 for i inrange(pre_p >> bits, pre_p >> (bits - 1)): q = pre_p // (i + 1) for bias inrange(-4, 5): r = q + bias if is_prime(r) and r.bit_length() == bits: return r print("Failed")
p, g = getSec(*sp, 1024), getSec(*sg, 1023) print(p) print(g)
unit = b"\x00" * 15 + b"\x01" A = bytes_to_long(unit * 8)
unit = b"\x00" * 16 B = bytes_to_long(b"\01" + unit * 8)
ap = pow(g, A * (p - 1), p ** 2) - 1 bp = pow(g, B * (p - 1), p ** 2) - 1
assertint(ap) % p == 0 assertint(bp) % p == 0
a, b = int(ap) // p, int(bp) // p C = (b * inverse(a, p)) % p S = int(pow(int(secret), p - 1, p ** 2)) - 1 assertint(S) % p == 0 S = ((int(S) // p) * inverse(a, p)) % p
M = matrix([[1/2**(768 - 128), 0, C], [0, 2**128, S], [0, 0, p]]) ML = M.LLL() print(ML) for v in ML: the_flag = abs((v * (2 ** (768 - 128)))[0]) print(long_to_bytes(int(the_flag)))