I'm using the rsa module (easy_install rsa), and if I use it from command line:

import rsa
public,private = rsa.gen_pubpriv_keys(3)
cipher=rsa.encrypt("test",public)
rsa.decrypt("cipher",private)

this will return test again. (like expected)
but in my code it gives a zlib error -3 incorrect headers

def RSA(txt):
    global crypt
    if crypt=="en":
        key=raw_input("Public key:")
        ciphertext=rsa.encrypt(txt,eval(key))
    else:
        key=raw_input("Private key:")
        ciphertext=rsa.decrypt(txt,eval(key))
    return ciphertext

I really don't know where the problem is =( txt is a string, eval(key) is a dict...
and it is btw only the decryption that fails, the encryption works like a charm...

please help me =)

Recommended Answers

All 3 Replies

are you using integers as the key? raw input returns strings which might be a problem. Convert it to integer and see. BTW I haven't used that module and so I don't know :)

I have to pass a dictionary trough raw_input,
but raw_input makes it a string so I thought using eval() it would convert to a dictionary? am I wrong @ this point?

I found out that I had lowercased every character in the text variable, this caused the error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.