A. Decrypt the Ciphertext: In this part you will create the content for the mappings.txt file. For that first run task5_1.c to perform frequency analysis on ciphertext.txt. This will generate frequency statistics for each letter
CP70045E M.Sc. Fundamentals of Cybersecurity Assignment 1 Brief |UWL
Question 1: Implementing RSA Key Generation Algorithm (20 pts)
Context: Read Task 1 from the RSA Lab document.
Follow the instructions provided to generate an RSA key pair. The bn_sample.c program demonstrates how to use OpenSSL's BIGNUM operations for mathematical computations. Using these OpenSSL functions, write a C program that fully implements RSA key generation.
Required:
A. Background (Max word count 300): Summarize the background of RSA encryption, including
o its fundamental principles and why it is widely used
o the role of prime numbers in key generation.
o the importance of modular exponentiation in encryption and decryption.
B. Write a C program named task1.c that performs the following:
- Generates two random 256-bit prime numbers (p, q).
- Computes the RSA modulus: N=p×q
- Computes Euler’s Totient Function: ϕ(N)=(p−1)×(q−1)
- Sets a public exponent (e = 65537).
- Computes the private exponent (d): d=e−1mod ϕ(N)
- Prints the values for:
o Generated primes (p, q)
o Modulus (N)
o Euler’s Totient (ϕ(N))
o Public exponent (e)
o Private exponent (d)
o Private exponent (d)
- Reveal keys: Write down your public key (e, N) and private key (d, N).
- Write the keys to keys.txt: Write down your keys to a file named keys.txt. This file content would be read I the subsequent questions.
Question 2: Encrypting and Decrypting Your Group Name (20 pts)
Context:
In Question 1, you generated an RSA key pair (N, e, d). Now, in Task 2, you will use the generated key values to first encrypt and then decrypt your “Group Name”
Required:
A. Find a unique group name for yourself, such as group_1, group_2, etc.
B. Write a C program named task2.c that takes plain text input, your group name, performs the following steps:
Step 1: Read public key from keys.txt file Read RSA Modulus (N) in hex format.
Read Public Exponent (e) in hex format. Read Private Exponent (d) in hex format.
Step 2: Convert Message to a BIGNUM
Convert the ASCII input message into a hexadecimal string. Convert the hex string into a BIGNUM.
Step 3: Encrypt the Message
Compute the ciphertext (C) using the RSA encryption formula: C=Me mod N
Print the ciphertext in hexadecimal format.
Step 4: Decrypt the Ciphertext
Compute the decrypted message (M) using the RSA decryption formula: M=Cd mod N
Print the decrypted message in hexadecimal format.
Step 5: Convert Decrypted Hex Back to ASCII
Convert the hexadecimal decrypted message back to ASCII.
Print the final decrypted message and verify that it matches the original input.
Deliverables:
- task2_c,
- screenshot of executing the task2_c.
Question 3: Implement RSA Digital Signing using OpenSSL (20 pts)
Context: In Q2 (previous task), you implemented RSA encryption and decryption. Now, in Q3, you will extend RSA to digital signatures, using the same key pair (e, d, N) from Q1.
Required:
Write a C program named task3.c that takes a message (Your message would be “I owe group_name $2000”) to sign and performs the following steps:
Step 1: Read Inputs
a. Read RSA Modulus (N) in hex format.
b. Read Private Exponent (d) in hex format.
Step 2: Convert the Message to a BIGNUM
- Convert ASCII input message (M) into hex format.
- Convert the hex string into a BIGNUM (M_bn).
Step 3: Generate the RSA Signature
- The digital signature (S) is created using: S=Mdmod N
- Print the signature (S) in hex format.
Step 4: Modify the Message and Sign Again
- Change "I owe group_name $2000." → "I owe group_name $3000."
- Sign the new message and compare both signatures. The resulting screenshot should look like below.
Q4: Implement RSA Signature Verification using OpenSSL (15 pts)
Context: In Q3, you implemented RSA signing using the private key (d, N).
Now, in Q4, you will implement RSA signature verification using the public key (e, N). This ensures that the message came from a valid signer and was not modified.
Required:
Develop task4.c (Signature Verification Program) which does the following.
Step 1: Read Inputs
- Prompt the user for the RSA Modulus (N) in hex format.
- Prompt the user for the Public Exponent (e) in hex format.
- Prompt the user for the Signature (S) in hex format.
- Prompt the user for the Original Message (M).
Step 2: Verify the Signature
- Compute: M′=Semod NM' = S^e \mod NM′=SemodN
- Convert M' back to ASCII and check if it matches the original message (M).
- If M' is different, the signature is invalid.
Step 3: Modify the Signature and Re-Verify
- Change one byte in S to simulate corruption.
- Repeat the verification and describe what happens.
Question 5: Frequency Analysis (20 pts) Context:
In this question you will analyze an encrypted message without knowing the encryption algorithm used. You will be provided with the following files: task5_1.c, task5_2.c, ciphertext.txt, and mappings.txt
- task5_1.c: This program performs frequency analysis on the encrypted text. It counts the occurrences of each letter and sorts them in descending order to help infer letter mappings.
- task5_2.c: This program applies the determined letter mappings to decrypt the text. It takes a mapping file as input and replaces each letter in the ciphertext accordingly.
- mappings.txt file is empty initially ( I will only provide sample row to show the format). It should have two columns each column containing a letter.
- ciphertext.txt: This file containsthe encrypted text.
Required:
A. Decrypt the Ciphertext: In this part you will create the content for the mappings.txt file. For that first run task5_1.c to perform frequency analysis on ciphertext.txt. This will generate frequency statistics for each letter, helping to determine the most probable letter mappings. Create mappings.txt based on the frequency analysis output. Compare the letter frequencies with typical English letter frequencies to infer the correct substitutions.
When you have the mappings.txt ready. run task5_2.c to decrypt the message using the mappings from mappings.txt. This will output the decrypted text. You can adjust mapping.txt file until you are happy with the result.
B. Reflection and Analysis (Max 250 words)
- Where did you encounter difficulties during the analysis?
- If the ciphertext were longer or shorter, would the decryption process be easier or more challenging?
- What strategies helped you determine the correct mappings?