133k views
0 votes
Write a program called keygen.py that accepts lo (int) and hi (int) as command-line arguments, generates public/private keys (n, e, d), and writes the keys to standard output, separated by a space. The interval [lo, hi) specifies the interval from which prime numbers p and q needed to generate the keys are picked. & ~/workspace/project4 $ python3 keygen . py 50 100 3599 1759 2839 Directions: Accept lo (int) and hi (int) as command-line arguments.

1 Answer

2 votes

Final answer:

The question pertains to creating a Python script named keygen.py that generates RSA encryption keys using prime numbers within a user-specified range, prints the public and private keys to standard output.

Step-by-step explanation:

The student is asking for a program written in Python that generates a pair of public and private keys for encryption, using prime numbers within a specified range. The range is provided as command-line arguments to the script.

The keys are generated based on the principles of RSA (Rivest-Shamir-Adleman) algorithm, which requires selecting two distinct prime numbers p and q.

From these primes, the program will calculate the modulus n = p * q, which is used as part of the public and private keys. The public exponent e is chosen such that it is relatively prime to (p-1)*(q-1), and the private exponent d is calculated to satisfy the condition d * e ≡ 1 mod (p-1)*(q-1).

After successful generation, the program will print the public key (n, e) and the private key (n, d), separated by space.

User Adam Kozlowski
by
8.4k points