A client-server application with confidential message exchange to provide authentication, integrity and key sharing among both the client and server with the help of RSA and Simplified AES algorithm.
The code execution requires python 3.x version installed on the system.
This repository consists of 2 files and 1 package which consists of 4 modules.
-
Util Package
-
This utitlity package contains all the required files for performing entire encryption and decryption.
-
The modules are:
-
-
- This file is for server side communication & decryption algorithm implementation
-
- This file is for client side communication & encryption algorithm implementation
RSA class for generating private and public key and rsa encryption and decryption algorithm
-
Imports
Operations
class object fromutil.Operations
-
Class methods
verifyParameters()
: Verify p and q as primes and e as valid number, returns boolgenerateKeys()
: Generates public and private key if key parameters are validated else exits the programencrypt()
: Encrypts the plaintext with private key and return the ciphertext listdecrypt()
: Decrypts the ciphertext with public key and returns the decrypted plaintextsign()
: Generates the client signature using client's private key and provided message digestverify()
: Decrypts the client signature using client's public key and verifies if generated message digest and decrypted client signature matchesprintHexList()
: Converts the ciphertext list into hex form
SAES class for generating subkeys and simplified aes encryption and decryption algorithm of the user's input message
-
Imports
Operations
class object fromutil.Operations
-
Class Methods
__perform_substitution()
: Returns substitued value after nibble substitution (S-Boxes) from the given substitution boxgenerate_subkeys()
: Generating subkeys from the given secret key - 16 bit int in the range of (1, 2^16-1)__initial_round()
: Adds round key implementation before round 1__convert_into_matrix()
: Converts the plaintext blocks list into matrix form (plaintext block (pair wise blocks of the entire text e.g ok!! => ['ok', '!!']))__perform_encryption_round()
: Performs 2 round of encryption by substituting nibbles, shifting rows, mixing columns if it is not the last round and then adding round keyencrypt()
: Method which is externally called to intiate the encryption process. This method calls the__initial_round()
,__convert_into_matrix()
and__perform_encryption_round()
methods to encrypt the given plaintext__perform_decryption_round()
: Performs 2 round of decryption by inverse shifting rows, Inverse Substitution,adding round key and then inverse mixing columns if it is not the last rounddecrypt()
: Method which is externally called to intiate the decryption process. This method calls the__initial_round()
,__convert_into_matrix()
and__perform_decryption_round()
methods to decrypt the given ciphertext
-
HashAlgo class for creating message digest using md5 hash algo
-
Imports
hashlib
(Built-in library)
-
Class Methods
generateHashCode()
: Generates hash code of the given message using md5 hash algorithm
-
Utitlity module which consists of all the mathematical operations and functions in Operations class used in RSA and SAES modules
-
Imports
random
(Built-in library)
-
Class Methods
isPrime()
: Verifies if the given no is primeisCoprime()
: Verifies if the givens numbers have their gcd 1gcd()
: Calculates the gcd of two numbers using Euclidien's algorithmmodInverse()
: Calculates the modular multiplicative inverse of a using modulo mshift_operation()
: Shifts the bits of the number to the left or right as directedcircular_left_shift()
: Rotates the bits of the given number to the left by the given shift amount
-
Imports
socket
,pickle
,RSA
,SAES
,HashAlgo
,Operations
-
Work flow
- Connects with the server
- Input user's message, secret key, and key parameters p, q and e
- requests and receives server public key from server (server.py)
- encrypts secret key
- encrypts plaintext into a ciphertext
- computes client signature by hasing message
- sends ciphertext, client signature, client's public key and ecrypted secret key to the server
-
Imports
socket
,pickle
,RSA
,SAES
,HashAlgo
,Operations
-
Work flow
- Connects with the client
- Input key parameters p, q and e
- accepts client's request and sends it's public key to client (client.py)
- recieves ciphertext, client signature, client's public key and ecrypted secret key from the client
- decrypts secret key
- decrypts ciphertext into a plaintext
- computes digital signature by hasing decrypted plaintext
- verifies client's signature
First run the server side
- run the server.py file
- Enter the key parameters
- run the client.py file
- Enter message
- Enter secret key
- Enter key parameters
- Type y to send request to the server for it's public key