jvdsn / crypto-attacks

Python implementations of cryptographic attacks and utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AMM method function rth_roots() get same roots

clingm opened this issue · comments

commented

When I tried to use this function to solve a CTF challenge, I found this problem.

from sage.all import *
from CryptoAttack.shared import rth_roots

c = 7267288183214469410349447052665186833632058119533973432573869246434984462336560480880459677870106195135869371300420762693116774837763418518542884912967719
e = 21
q = 9908484735485245740582755998843475068910570989512225739800304203500256711207262150930812622460031920899674919818007279858208368349928684334780223996774347
print(list(rth_roots(GF(q), c, e)))

I got this output

[5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446]

all roots is 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446.

but when I made this change

def roots_of_unity(ring, l, r):
    """
    Generates r-th roots of unity in a ring, with r | l.
    :param ring: the ring, with order n
    :param l: the Carmichael lambda of n
    :param r: r
    :return: a generator generating the roots of unity
    """
    assert l % r == 0, "r should divide l"

    x = ring(3)
    while x ** l != 1:
        x += 1
    print(x)
    g = x ** (l // r)
    for i in range(r):
        yield int(g ** i)

I replace the initial value of x with 3, I got the right solution

[5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 280144707245011294640488506115562281365276356125932100207397393027860909029413220156776010197352605708589655905445419432143442931322397721593647968474277, 7430474113276965115422561010012825056649819720622305012119305319337399559413055056545816300802245496064549287797757557077547908297143373105085421303274867, 4563675787323427286374907245468529995244053214707683042368598801135429713200620060437513752829145989678698319665342340325183439671079059924144916004756970, 2798072739863399815101890848589737393172952179316532589269644554919015010733862014492230886774517981425049058508156951568239808827156512588164729805156879, 9391573497164348797642157544159683077847387626417455197573630359125733460335703475872083705628619684219006073476648010518321422909263199325412678307023692, 154110187494616397671066227097770386558859787802617565773755349387989231317636267478296013662932004413507040541332089184010995557074142252157423736369910, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 280144707245011294640488506115562281365276356125932100207397393027860909029413220156776010197352605708589655905445419432143442931322397721593647968474277, 7430474113276965115422561010012825056649819720622305012119305319337399559413055056545816300802245496064549287797757557077547908297143373105085421303274867, 4563675787323427286374907245468529995244053214707683042368598801135429713200620060437513752829145989678698319665342340325183439671079059924144916004756970, 2798072739863399815101890848589737393172952179316532589269644554919015010733862014492230886774517981425049058508156951568239808827156512588164729805156879, 9391573497164348797642157544159683077847387626417455197573630359125733460335703475872083705628619684219006073476648010518321422909263199325412678307023692, 154110187494616397671066227097770386558859787802617565773755349387989231317636267478296013662932004413507040541332089184010995557074142252157423736369910, 5107403174087968514895196615086317015893364083544151712088580833567342249591496357809721197485282001189625323559339471469178086856747368087781854865266446, 280144707245011294640488506115562281365276356125932100207397393027860909029413220156776010197352605708589655905445419432143442931322397721593647968474277, 7430474113276965115422561010012825056649819720622305012119305319337399559413055056545816300802245496064549287797757557077547908297143373105085421303274867, 4563675787323427286374907245468529995244053214707683042368598801135429713200620060437513752829145989678698319665342340325183439671079059924144916004756970, 2798072739863399815101890848589737393172952179316532589269644554919015010733862014492230886774517981425049058508156951568239808827156512588164729805156879, 9391573497164348797642157544159683077847387626417455197573630359125733460335703475872083705628619684219006073476648010518321422909263199325412678307023692, 154110187494616397671066227097770386558859787802617565773755349387989231317636267478296013662932004413507040541332089184010995557074142252157423736369910]

Thanks for the report. This should be fixed in the latest commit.