Stereotyped messages Attack code on SageMath can't find answer

28 views Asked by At
import time
import sys

def long_to_bytes(data):
    data = str(data)[2:]
    return "".join([chr(int(data[i:i + 2])) for i in range(0, len(data), 2)])
    
def bytes_to_long(data):
    return int.from_bytes(data.encode('ascii'), byteorder='big')

def main():
    e, N = (3, 16314174597670070489683800576799378406896534352670351262539770188412623420182531137341191182375514311220629154509823704709051837420817414261133074921733903228385453841150313788172315847851283199096037806063857461308014479969934237602876327981195311881343929165575382436626969277333504937263147493508170454671070721932789664320193044257000628986862751315722915346173795087082663358648621044038881942733083604577128722176583897981221815071046972470211521922824024802322386037605096868502625128038638756529680674487325331818869882713411857472086639942976435045357800636891495474405820598645940238582061163889140265309553)
    c = 7189774276796655515350593057269240658282205848992865316365016094995326443128491792227346760997449602964414192965015173537864718618571198038832378707650829024629223762680932897327355081768530289636916664261296683060430531125313048182754845616056305707426434398961714806216473860205312349253608386273704511446435983265711812818176387449149679710484433247071271146859184339698868316225905821099774039902358142535483465030117778341980488048152666115279211303729638254755769165184110542132881479036695720400144472373203867757779347646691458924398807653381404576598987566467380635741070537417145200971443232379811147216793
    m = bytes_to_long("Did you know that RSA stands to Really Secure Algorithm? It's really secure! The passcode: 00000000000000000000000000000000")

    P.<x> = PolynomialRing(Zmod(N), implementation='NTL')
    pol = (m + x)^e - c
    roots = pol.small_roots(X=10^1000, epsilon=1/30)
    print("Potential solutions:", len(roots))
    for root in roots:
       print(root, long_to_bytes(m+root))
    
    print("done")
    
main()

This code used Streotyped message Attack. It's fit to the attack's rule.

  • e=3

  • x<N^(1/e)

How can I solve it?

I tried to make epsilon smaller, but It doesn't work. The code stopped and didn't print anything.

0

There are 0 answers