p = getPrime(128) Fp = GF(p) a = Fp(getPrime(32)) y = Fp(getPrime(32)) b = a ^ y print(f'{p = }') print(f'{a = }') print(f'{y = }') print(f'{b = }') """ p = 308246233383857285750026618406218229381 a = 2189570113 y = 2989311631 b = 157894317370901577057351162302392667811 """
result = bsgs(mod(a, p), mod(b, p), bounds=(2**31, 2**32)) print(f'{result = }') """ result = 2989311631 """
p = 6897108443075981744484758716081045417854227543713106404294789655180105457499042179717447342593790180943415014044830872925165163457476209819356694244840079 b = 1315637864146686255246675143589215932218700984880749264689270214639479160648747323586062096067740047809798944996253169402675772469028914904598116394230426 a = 6789891305297779556556571922812978922375073901749764215969003309869718878076269545304055843125301553103531252334876560433405451108895206969904268456786139
n = p - 1 primes = list(filter(lambda x: x < 2 ** 32, (base ** exp for base, exp in factor(n)))) dlogs = [] for fac in primes: t = int(n) // int(fac) dlog = discrete_log(pow(b, t, p), pow(a, t, p)) dlogs.append(dlog) yp = int(crt(dlogs, primes)) print(yp)