Skip to main content

A simpler plug and play module for prototyping cryptography techniques

Project description

PyCryptoMod

Simple Package for working with generic ciphers

Usage:

General Ciphers

Caeser Cipher

    # Example usage:

    plaintext = "Hello, World!"
    key = 3
    encrypted_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 Ciphers

AES

    # Example usage:

    plaintext = "Hello, AES!"
    key = get_random_bytes(16)  # 128-bit key
    print("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 key
    print("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 3DES
    print("Plaintext:", plaintext)

    ciphertext = triple_des_encrypt(plaintext, key)
    print("Ciphertext:", ciphertext.hex())

    decrypted_text = triple_des_decrypt(ciphertext, key)
    print("Decrypted:", decrypted_text)

Asymetric Ciphers

RSA

    #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 purposes
    g = 5   # A primitive root modulo p

    # Alice and Bob perform Diffie-Hellman key exchange
    alice_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 key
    shared_secret_alice = (bob_public_key ** alice_private_key) % p
    shared_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 secret
    aes_key = derive_aes_key(str(shared_secret_bytes))

    # Use the derived AES key for AES encryption and decryption
    plaintext = "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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycryptomod-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycryptomod-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pycryptomod-0.1.0.tar.gz.

File metadata

  • Download URL: pycryptomod-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for pycryptomod-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2464d418c8737e956b375514447c70a8052d68e40ae4858d34a001747cc7a93
MD5 1ef5e8dec2486db1bdb3fc54c8d62f71
BLAKE2b-256 84fd6a1cb395440fd153b324fa28e55207b23d40e81b055e40cf15d2f20317a7

See more details on using hashes here.

File details

Details for the file pycryptomod-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycryptomod-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for pycryptomod-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e53bb29ece7e0817627a94c47a2cdaec5019fd50eecb6270ac47d90d5a21408f
MD5 42607a8e622d5b7e9272d2c24c185f93
BLAKE2b-256 34d565c68f24871d6a62a9686b05c66986c82d7162af53adf8567b4bb1d973f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page