Return to site

Rsa decrypt with public key python crypto

broken image

e = random.randint( 2, phi_n - 1) while math.gcd(e, phi_n) != 1: e = random.randint( 2, phi_n - 1) # Choose d such that e * d % phi_n = 1. phi_n = (p - 1) * (q - 1) # Since e is chosen randomly, we repeat the random choice # until e is coprime to phi_n. Preconditions: - p and q are prime - p != q ''' # Compute the product of p and q n = p * q # Choose e such that gcd(e, phi_n) = 1.

broken image

The second tuple is the public key, containing (n, e). The first tuple is the private key, containing (p, q, d).

broken image

The return value is a tuple containing two tuples: 1.

broken image

\newcommandĭef rsa_generate_key(p: int, q: int) -> \ tuple, tuple]: '''Return an RSA key pair generated using primes p and q.

broken image