Skip to content

πŸ—οΈ Implementation of famous cryptography algorithms over computer networks. πŸ”πŸ”‘

Notifications You must be signed in to change notification settings

ChiragRadhakrishna43-7/Cryptography

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

1. Knapsack Encryption


The Merkle–Hellman knapsack cryptosystem was one of the earliest public key cryptosystems. It was published by Ralph Merkle and Martin Hellman in 1978. (Source: Wikipedia)

STEP 1: DEFINE A SUPER-INCREASING SEQUENCE-
The super-increasing sequence is the user's private key. Screenshot 2024-06-08 155257

STEP 2: DEFINE FUNCTIONS THAT GENERATE q AND r VALUES-
These two variables help generate the public key & are actively used in decryption. Screenshot 2024-06-08 155700

STEP 3: DEFINE THE PUBLIC-KEY FUNCTION-
The public key is a non-super increasing sequence. Screenshot 2024-06-08 155905

STEP 4: ENCRYPTION FUNCTION IMPLEMENTATION-
The encrypted ciphertext is an integer.
Screenshot 2024-06-08 160259

STEP 5: DECRYPTION-
Compute r inverse. There are several ways to calculate and obtain the inverse of r. Using the extended Euclidean algorithm is one example.
Screenshot 2024-06-08 161138

2.AES Encryption


Implementation of a symmetric encryption scheme using the AES (Advanced Encryption Standard) algorithm, with additional functionality for padding and unpadding plaintext data.

Main Functions-

encrypt_f(plain_txt, shared_secret): Encrypts a plaintext message plain_txt using a shared secret key shared_secret.
The encryption process involves:
Padded the plaintext using a block size of AES.block_size (typically 16 bytes). Generating a random initialization vector (IV) of the same size as the block size. Encrypting the padded plaintext using AES in CBC mode with the shared secret key and the IV. Encoding the encrypted data using Base64.


decrypt_f(cipher_txt, shared_secret): Decrypts a ciphertext message cipher_txt using a shared secret key shared_secret.
The decryption process involves:
Decoding the Base64-encoded ciphertext. Extracting the IV from the beginning of the decoded data. Decrypting the ciphertext using AES in CBC mode with the shared secret key and the IV. Unpadding the decrypted plaintext using a custom function.


Additional Functions-

pad(plain_text):Adds padding to the plaintext data to ensure it is aligned with the AES block size.

unpad(plain_txt):Removes padding from the decrypted plaintext data.

int_to_bytes(integer):Converts an integer to a bytes object.

Notes-

The shared_secret key is used as input to both encryption and decryption functions. This key is assumed to be shared between the parties involved in the encryption and decryption process. The hashlib.sha256 function is used to generate a hash of the shared secret key, which is then used as the encryption key. The code uses the AES module from the cryptography library, which provides an implementation of the AES algorithm. The get_random_bytes function generates a random bytes object of the same size as the AES block size.

About

πŸ—οΈ Implementation of famous cryptography algorithms over computer networks. πŸ”πŸ”‘

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages