
#of composite numbers from our potential pool without resorting to Rabin-Miller taking n modulo each lowPrime allows us to remove a huge chunk #lowPrimes is all primes (sans 2, which is covered by the bitwise and operator) Print ("Decrypting message with public key ", public ,". 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 Print (''.join(map(lambda x: str(x), encrypted_msg)))ĭecryption code: def decrypt(k,pk, ciphertext): Print ("Your public key is ", public ," and your private key is ", private)Įncrypted_msg = encrypt(private, message) Print ("Generating your public/private keypairs now. #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.') When i use the public key for decryption the data is wrong!! i have also try use private same also wrong!! any suggestion !

Is there away to solve this problem even the code is work prefect for encrypted and decrypted the data when they are in same file, the problem happen when i divide the code into two parts, one part encryption and second part decryption, but still i'm getting wrong decryption data even i use same public key and n value was generated in encryption part.
