Untitled

mail@pastecode.io avatar
unknown
python
a year ago
1.5 kB
6
Indexable
Never
# hint = [secret * muls[i] % mods[i] for i in range(20)]
# 
# print(f"hint = {xorrrrr(hint)}")
# print(f"muls = {xorrrrr(muls)}")
# print(f"mods = {xorrrrr(mods)}")
# 

def recover(nums):
    n = len(nums)
    xor_all = 0
    for num in nums:
        xor_all ^= num
    for i in range(len(nums)):
        nums[i] ^= xor_all
    return nums

hint = [297901710, 2438499757, 172983774, 2611781033, 2766983357, 1018346993, 810270522, 2334480195, 154508735, 1066271428, 3716430041, 875123909, 2664535551, 2193044963, 2538833821, 2856583708, 3081106896, 2195167145, 2811407927, 3794168460]
muls = [865741, 631045, 970663, 575787, 597689, 791331, 594479, 857481, 797931, 1006437, 661791, 681453, 963397, 667371, 705405, 684177, 736827, 757871, 698753, 841555]
mods = [2529754263, 4081964537, 2817833411, 3840103391, 3698869687, 3524873305, 2420253753, 2950766353, 3160043859, 2341042647, 4125137273, 3875984107, 4079282409, 2753416889, 2778711505, 3667413387, 4187196169, 3489959487, 2756285845, 3925748705]

hint = recover(hint)
muls = recover(muls)
mods = recover(mods)

print(hint)
print(muls)
print(mods)

remainders = [(hint[i] * pow(muls[i], -1, mods[i])) % mods[i] for i in range(20)]
print(remainders)
mod_product = 1
for mod in mods:
    mod_product *= mod
print(f"mod_product: {mod_product}")

# Chinese remainder theorem
ans = 0
for i in range(20):
    ans += remainders[i] * pow(mod_product // mods[i], -1, mods[i]) * mod_product // mods[i]
ans %= mod_product
print(f'ans: {ans.to_bytes(128, "big")}')