Package: pycryptomod
PyCryptoModSimple Package for working with generic ciphersUsage:General CiphersCaeser Cipher# Example usage:plaintext="Hello, World!"key=3encrypted_text=caesar_cipher(plaintext,key)print("Encrypted:",encrypted_text)decrypted_text=caesar_cipher(encrypted_text,key,decrypt=True)print("Decrypted:",decrypted_text)Monoalphabetic Cipher# Example usage:encrypted_text=monoalphabetic_cipher(plaintext,key)print("Encrypted:",encrypted_text)decrypted_text=monoalphabetic_cipher(encrypted_text,key,decrypt=True)print("Decrypted:",decrypted_text)Vignere Cipher# Example usage:plaintext="HELLO"keyword="KEY"print("Plaintext:",plaintext)print("Keyword:",keyword)encrypted_text=vigenere_cipher(plaintext,keyword)print("Encrypted:",encrypted_text)decrypted_text=vigenere_cipher(encrypted_text,keyword,decrypt=True)print("Decrypted:",decrypted_text)Symetric CiphersAES# Example usage:plaintext="Hello, AES!"key=get_random_bytes(16)# 128-bit keyprint("Plaintext:",plaintext)ciphertext=aes_encrypt(plaintext,key)print("Ciphertext:",ciphertext.hex())decrypted_text=aes_decrypt(ciphertext,key)print("Decrypted:",decrypted_text)DES# Example usage:plaintext="Hello, DES!"key=get_random_bytes(8)# 64-bit keyprint("Plaintext:",plaintext)ciphertext=des_encrypt(plaintext,key)print("Ciphertext:",ciphertext.hex())decrypted_text=des_decrypt(ciphertext,key)print("Decrypted:",decrypted_text)DES3:# Example usage:plaintext="Hello, 3DES!"key=get_random_bytes(24)# 192-bit key for 3DESprint("Plaintext:",plaintext)ciphertext=triple_des_encrypt(plaintext,key)print("Ciphertext:",ciphertext.hex())decrypted_text=triple_des_decrypt(ciphertext,key)print("Decrypted:",decrypted_text)Asymetric CiphersRSA#Example Usage(generate using a simple p and q):public,pvt=generateMinRSA_keys(11,13)plaintext="Hello World"cipher=MinRSA_encrypt(plaintext,public)print(cipher)print(MinRSA_decrypt(cipher,pvt))# Example usage(Signature Verification):message_to_sign="This is a signed message."signature=create_rsa_signature(message_to_sign,private_key)is_valid_signature=verify_rsa_signature(message_to_sign,signature,public_key)print("Signature is valid:",is_valid_signature)# Example usage(Key Generation):plaintext="Hello, RSA!"keypair=generate_rsa_keypair()public_key=keypair.publickey()private_key=keypair# Example usage(RSA using pycryptodome):ciphertext=rsa_encrypt(plaintext,public_key)decrypted_message=rsa_decrypt(ciphertext,private_key)print("Decrypted message:",decrypted_message)Diffie Hellman# Example usage:p=23# A small prime number for demonstration purposesg=5# A primitive root modulo p# Alice and Bob perform Diffie-Hellman key exchangealice_private_key,alice_public_key=diffie_hellman(p,g)bob_private_key,bob_public_key=diffie_hellman(p,g)# Both Alice and Bob compute the shared secret keyshared_secret_alice=(bob_public_key**alice_private_key)%pshared_secret_bob=(alice_public_key**bob_private_key)%p# Convert the shared secret to bytes (for AES key)shared_secret_bytes=shared_secret_alice.to_bytes((shared_secret_alice.bit_length()+7)//8,byteorder='big')# Derive AES key from shared secretaes_key=derive_aes_key(str(shared_secret_bytes))# Use the derived AES key for AES encryption and decryptionplaintext="Hello, Diffie-Hellman!"ciphertext,tag,nonce=aes_encrypt(plaintext,aes_key)decrypted_text=aes_decrypt(ciphertext,tag,nonce,aes_key)print("Original:",plaintext)print("Decrypted:",decrypted_text)