Avadhut4-merged
Avadhut4-merged
1. Implementation of S-DES.
Code :
def pad(text):
while len(text) % 8 != 0:
text += " "
return text
plaintext = "Hello123"
padded_text = pad(plaintext)
# Encrypt
encrypted_text = cipher.encrypt(padded_text.encode())
print("Encrypted:", binascii.hexlify(encrypted_text))
# Decrypt
decrypted_text = cipher.decrypt(encrypted_text).decode().strip()
print("Decrypted:", decrypted_text)
Output :
Pratical No : 2
Code :
# Pad the data to make it a multiple of AES block size (16 bytes)
padded_data = pad(data.encode(), AES.block_size)
Output :
Pratical No : 3
Code :
import random
# Function to generate a large prime number for the Diffie-Hellman key exchange
def generate_prime(bits=2048):
# For simplicity, using a library to generate large primes (or you can use an existing prime)
# In a real-world scenario, you'd use a cryptographic library to generate this securely.
# For now, we'll use a small prime for demonstration purposes.
# The larger the prime, the more secure the exchange.
return 23 # Small prime example for demonstration (replace with a real large prime in
production)
# Step 2: Generate private keys for Alice and Bob (randomly selected)
alice_private_key = random.randint(1, p-1)
bob_private_key = random.randint(1, p-1)
Output :
Pratical No : 4
Code :
return ciphertext
return plaintext
# Example Usage
# Step 1: Generate RSA keys
private_key, public_key = generate_rsa_keys()
Output :