




Your confusion comes from the function name: Actually, the modular multiplicative inverse is calculated here, which is far more complicated than the "normal" inverse you described. I haven't seen a None return in my calculations yet. If all previous numbers are correct, it should give a number as output. The multiplicative_inverse() can return None right? How do you deal with that?Īlso, please can you explain that function? Isn't a multiplicative inverse of a number p/q supposed to be q/p so that it's product is 1? Print "Decrypting message with public key ", public, ". join( map( lambda x: str( x), encrypted_msg)) Message = raw_input( "Enter a message to encrypt with your private key: ")Įncrypted_msg = encrypt( private, message) Print "Your public key is ", public, " and your private key is ", private Public, private = generate_keypair( p, q) Print "Generating your public/private keypairs now. Q = int( raw_input( "Enter another prime number (Not one you entered above): ")) P = int( raw_input( "Enter a prime number (17, 19, 23, etc): ")) Plain = ĭetect if the script is being run directly by the user #Generate the plaintext based on the ciphertext and key using a^b mod m #Convert each letter in the plaintext to numbers based on the character using a^b mod mĬipher = #Public key is (e, n) and private key is (d, n) #Use Extended Euclid's Algorithm to generate the private key #Use Euclid's Algorithm to verify that e and phi(n) are comprime #Choose an integer e such that e and phi(n) are coprime Raise ValueError( 'p and q cannot be equal') Raise ValueError( 'Both numbers must be prime.') Use iteration to make it faster for larger integersĮuclid's extended algorithm for finding the multiplicative inverse of two numbersįor n in xrange( 3, int( num ** 0.5) + 2, 2): In PHP there's a openssl_public_decrypt function that decrypts this data easily.Euclid's algorithm for determining the greatest common divisor I'm calling it with the path to the public key file (in OpenSSH format.) The encrypted data isn't generated by me and it was not done with Python but PHP. The code is this: def _decrypt_rsa(decrypt_key_file, cipher_text):ĭecrypted = crypt(raw_cipher_data) When I try to decrypt using P圜rypto I get No private key error from P圜rypto. The data is not really secret but I need to guarantee that it was created by the owner of the public (and private) key. In my case, I want to ensure authenticity so I encrypt the data with the private key and allow anyone to decrypt it with the public key. As far as I understand, I should be able to use RSA to ensure authenticity or privacy, as I wish.
