Expert Cryptography Assignment Help: Solving Complex Cryptographic Challenges

At ProgrammingHomeworkHelp.com, we specialize in providing comprehensive online cryptography assignment help to students. Cryptography, a fundamental aspect of securing information in the digital age, involves complex mathematical theories and practical applications. Our team of experts is adept at handling intricate cryptographic problems and providing clear, detailed solutions. Below, we present a sample post featuring two master-level cryptography questions along with their solutions, showcasing the depth of expertise available at ProgrammingHomeworkHelp.com.

Problem 1: Implementing the RSA Algorithm

Question:

In this assignment, you are required to implement the RSA encryption and decryption algorithm in Python. The RSA algorithm involves key generation, encryption, and decryption processes. Your task is to write a Python program that:
1. Generates a pair of RSA keys.
2. Encrypts a given plaintext message using the public key.
3. Decrypts the ciphertext back to the original message using the private key.

The program should include functions for key generation, encryption, and decryption. Use the following specifications:
- Choose two prime numbers, \( p \) and \( q \), such that \( p = 61 \) and \( q = 53 \).
- The plaintext message to be encrypted is "CRYPTOGRAPHY".
- Implement the algorithm using basic Python without relying on external libraries for cryptographic functions.

Solution:
To implement the RSA algorithm in Python, we follow these steps: key generation, encryption, and decryption.

Step 1: Key Generation

1. Choose two prime numbers \( p \) and \( q \)
   - \( p = 61 \)
   - \( q = 53 \)

2. Compute \( n \)
   - \( n = p \times q = 61 \times 53 = 3233 \)

3. Compute \( \phi(n) \) (Euler's Totient Function):
   - \( \phi(n) = (p-1) \times (q-1) = 60 \times 52 = 3120 \)

4. Choose an integer \( e \) such that \( 1 < e < \phi(n) \) and \( e \) is coprime with \( \phi(n) \):
   - Let \( e = 17 \)

5. Compute \( d \), the modular multiplicative inverse of \( e \) modulo \( \phi(n) \):
   - \( d \times e \equiv 1 \ (\text{mod} \ \phi(n)) \)
   - \( d = 2753 \) (calculated using the Extended Euclidean Algorithm)

Step 2: Encryption

- Convert the plaintext message to numerical form:
  - "CRYPTOGRAPHY" can be represented as numerical values using a simple scheme (e.g., A=1, B=2, ..., Z=26). However, for simplicity, let's directly encrypt each character based on its ASCII value.

- Encrypt each character:
  - For each character in the plaintext, \( \text{ciphertext} = \text{char}^e \ (\text{mod} \ n) \)

Step 3: Decryption

- Decrypt each character:
  - For each character in the ciphertext, \( \text{plaintext} = \text{char}^d \ (\text{mod} \ n) \)

Here is the complete Python implementation:

```python
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def mod_inverse(e, phi):
    def extended_gcd(a, b):
        if a == 0:
            return b, 0, 1
        gcd, x1, y1 = extended_gcd(b % a, a)
        x = y1 - (b // a) * x1
        y = x1
        return gcd, x, y
    gcd, x, _ = extended_gcd(e, phi)
    if gcd != 1:
        raise Exception('Modular inverse does not exist')
    else:
        return x % phi

def generate_keys(p, q):
    n = p * q
    phi = (p - 1) * (q - 1)
    e = 17
    while gcd(e, phi) != 1:
        e += 2
    d = mod_inverse(e, phi)
    return ((e, n), (d, n))

def encrypt(public_key, plaintext):
    e, n = public_key
    ciphertext = [(ord(char) ** e) % n for char in plaintext]
    return ciphertext

def decrypt(private_key, ciphertext):
    d, n = private_key
    plaintext = ''.join([chr((char ** d) % n) for char in ciphertext])
    return plaintext

p = 61
q = 53
public_key, private_key = generate_keys(p, q)

plaintext = "CRYPTOGRAPHY"
ciphertext = encrypt(public_key, plaintext)
decrypted_message = decrypt(private_key, ciphertext)

print("Original Message:", plaintext)
print("Encrypted Message:", ciphertext)
print("Decrypted Message:", decrypted_message)
```

Explanation:
- Key Generation: We generate the public and private keys using the given prime numbers \( p \) and \( q \). The public key is \( (e, n) \) and the private key is \( (d, n) \).
- Encryption: The plaintext message "CRYPTOGRAPHY" is converted to ciphertext using the public key.
- Decryption: The ciphertext is converted back to the original message using the private key.

This implementation demonstrates the core principles of the RSA algorithm and provides a clear example of how cryptographic techniques can be applied programmatically.

Problem 2: Implementing the AES Algorithm in CBC Mode

Question:

In this assignment, you are required to implement the Advanced Encryption Standard (AES) algorithm in Cipher Block Chaining (CBC) mode using Python. The AES algorithm is a symmetric key encryption algorithm. Your task is to write a Python program that:
1. Encrypts a given plaintext message using AES in CBC mode.
2. Decrypts the ciphertext back to the original message.

Use the following specifications:
- Use a 128-bit key.
- Use an initialization vector (IV) of 16 bytes.
- The plaintext message to be encrypted is "ADVANCEDCRYPTOSYSTEM".
- Implement the algorithm using the `pycryptodome` library.

Solution:

To implement AES in CBC mode in Python, we will use the `pycryptodome` library, which provides robust cryptographic functionalities.

Step 1: Install `pycryptodome`

Ensure you have `pycryptodome` installed in your Python environment. You can install it using pip:

```bash
pip install pycryptodome
```

Step 2: Implement the AES Encryption and Decryption

1. Generate a 128-bit key and a 16-byte IV.
2. Encrypt the plaintext using AES in CBC mode.
3. Decrypt the ciphertext back to the original message.

Here is the complete Python implementation:

```python
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes

def aes_encrypt(plaintext, key, iv):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    padded_plaintext = pad(plaintext.encode(), AES.block_size)
    ciphertext = cipher.encrypt(padded_plaintext)
    return ciphertext

def aes_decrypt(ciphertext, key, iv):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    padded_plaintext = cipher.decrypt(ciphertext)
    plaintext = unpad(padded_plaintext, AES.block_size)
    return plaintext.decode()

key = get_random_bytes(16)  # 128-bit key
iv = get_random_bytes(16)   # 16-byte IV

plaintext = "ADVANCEDCRYPTOSYSTEM"
ciphertext = aes_encrypt(plaintext, key, iv)
decrypted_message = aes_decrypt(ciphertext, key, iv)

print("Original Message:", plaintext)
print("Encrypted Message:", ciphertext)
print("Decrypted Message:", decrypted_message)
```

Explanation:
- Key and IV Generation: We generate a 128-bit key and a 16-byte initialization vector (IV) using `get_random_bytes`.
- Encryption: The plaintext message "ADVANCEDCRYPTOSYSTEM" is padded and then encrypted using AES in CBC mode.
- Decryption: The ciphertext is decrypted back to the original message by removing the padding.

The `pycryptodome` library simplifies the implementation of cryptographic algorithms, ensuring secure encryption and decryption processes. This example highlights the application of AES in CBC mode, a widely used encryption standard.

Conclusion

At ProgrammingHomeworkHelp.com, our experts are equipped to tackle complex cryptographic challenges, offering online cryptography assignment help to students at all levels. Whether you need assistance with implementing algorithms like RSA and AES or understanding the theoretical foundations of cryptography, our team is here to support your academic journey. By providing detailed solutions and clear explanations, we ensure that you gain a thorough understanding of cryptographic principles and their practical applications.

For any cryptography assignments or further inquiries, feel free to reach out to our experts. We are committed to helping you succeed in your studies and excel in the field of cryptography.

Log in to leave a reply.