Skip to content

Instantly share code, notes, and snippets.

@maple3142
Created July 20, 2022 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maple3142/6b6db9bcb4ecfc8b0e2460621c8abef5 to your computer and use it in GitHub Desktop.
Save maple3142/6b6db9bcb4ecfc8b0e2460621c8abef5 to your computer and use it in GitHub Desktop.
FCSC 2022 - Some challenge about python hash that I don't remember its name
p1 = 11400714785074694791
p2 = 14029467366897019727
p5 = 2870177450012600261
mask = (1 << 64) - 1
def rol(x, l):
return ((x << l) | (x >> (64 - l))) & mask
def tuplehash(tup):
acc = p5
for x in tup:
lane = hash(x)
acc += lane * p2
acc &= mask
acc = rol(acc, 31)
acc *= p1
acc &= mask
acc += len(tup) ^ (p5 ^ 3527539)
acc &= mask
if acc & (1 << 63):
acc -= 1 << 64
return acc
from random import randint
def find_preimage_tuple(target):
while True:
M = 2**64
a = randint(1, 1 << 60)
t = rol(((target - (2 ^ p5 ^ 3527539)) & mask) * pow(p1, -1, M) % M, 33)
s = (rol((p5 + a * p2) & mask, 31) * p1) & mask
b = (t - s) * pow(p2, -1, M) % M
if hash(a) == a and hash(b) == b and hash((a,b)) == target:
return (a,b)
find_preimage_tuple(hash('flag'))
# FCSC{658232b18ebebc53c42dd373c6e9bc788f1fd5693cf8a45bcafbff46dae42e24}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment