K
K
korsamc2017-12-07 17:28:56
Python
korsamc, 2017-12-07 17:28:56

RSA 576 bit how to decrypt?

Good day, I need help deciphering the text or an indication of an error in completing the task, I am going through a challenge on the root-me.org website, where the public key and ciphertext are given:

-----BEGIN PUBLIC KEY-----
MGQwDQYJKoZIhvcNAQEBBQADUwAwUAJJAMLLsk/b+SO2Emjj8Ro4lt5FdLO6WHMM
vWUpOIZOIiPu63BKF8/QjRa0aJGmFHR1mTnG5Jqv5/JZVUjHTB1/uNJM0VyyO0zQ
owIDAQAB
-----END PUBLIC KEY-----

e8oQDihsmkvjT3sZe+EE8lwNvBEsFegYF6+OOFOiR6gMtMZxxba/bIgLUD8pV3yEf0gOOfHuB5bC3vQmo7bE4PcIKfpFGZBA

Using Python and the pycrypto library, I pulled the n module from the key:
from Crypto.PublicKey import RSA
key = RSA.importKey(open('pubkey.pem').read())
print('n = ',key.n)
print('e = ',key.e)

where n = 188198812920607963838697239461650439807163563379417382700763356422988859715234665485319060606504743045317388011303396716199692321205734031879550656996221305168759307650257059
e = 65537
Further Googling about the factorization I came across the RSA Factoring Challenge, where he found the required module, which corresponds to the RSA-576, and there is also a factorization of numbers. Having all this data, I used wikipedia and python implemented the secret key calculation.
def egcd(a, b):
    x,y,u,v = 0,1,1,0
    while a != 0:
        q, r = b // a, b % a
        m, n = x - u * q, y - v * q
        b,a,x,y,u,v = a,r,u,v,m,n
    return b, x, y

def modinv(e, m):
    g, x, y = egcd(e, m)
    if g != 1:
        return None
    else:
        return x % m

def pqe2rsa(p, q, e):
    n = p * q
    phi = (p - 1) * (q - 1)
    d = modinv(e, phi)
    key_params = (int(n), int(e), int(d), int(p), int(q))
    priv_key = RSA.construct(key_params)
    with open('privkey.pem', 'wb') as f:
        f.write(priv_key.exportKey())

which gave me this output:
-----BEGIN RSA PRIVATE KEY-----
MIIBXwIBAAJJAMLLsk/b+SO2Emjj8Ro4lt5FdLO6WHMMvWUpOIZOIiPu63BKF8/Q
jRa0aJGmFHR1mTnG5Jqv5/JZVUjHTB1/uNJM0VyyO0zQowIDAQABAkgyAw5Cxp1O
d95+I5exPbouUvLFeiBfWXP+1vh2MvU8+IhmCf9j+hFOK13x22JJ+Orwv1+iatW4
5It/qwUNMvxXS0RuItCLp7ECJQDM6VRX8SfElUbleEECmsavcGBMZOgoEBisu1OC
M7tX83puaJUCJQDzXLgl8AM5bxHxSaWaD+c9tDFiyzBbjr/tpcqEC+JMU2tqrlcC
JQCjGt8+GQD0o3YJVc05i4W3RBYC+RcqPJXHeFyieRcYjP/ZPnkCJQDVUULBTl8l
KuzJWcrk/metuJNJi925g6lMwHSBxoD4cm7HtkUCJFqWTOzCIODw7eoypcJYjm2O
/ohEsSjEXsg6Bh8mY3LunBaqiA==
-----END RSA PRIVATE KEY-----

and further, to decrypt the source text, I decided to use Openssl in Ubuntu
openssl rsautl -decrypt -in ciphertext -out text -inkey privkey.pem

To which the program tells me "Error reading the incoming file"
Or maybe by the evening my head does not cook and I really did some primitive thing wrong than I don’t know anything else, help with practical advice!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
korsamc, 2017-12-13
@korsamc

I found the answer as follows, maybe I didn’t copy the factorization from Wikipedia correctly, transferred it to the code, recompiled everything and decrypted it using https://8gwifi.org/rsafunctions.jsp of this service. The answer turned out to be: up2l6DnaIhZgxA

J
jcmvbkbc, 2017-12-07
@jcmvbkbc

Tells me

RSA operation error
140624383731344:error:0406506C:rsa routines:RSA_EAY_PRIVATE_DECRYPT:data greater than mod len:rsa_eay.c:518:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question