- Notifications
You must be signed in to change notification settings - Fork4
The repo is about simple implementation of various algorithms and techniques used in cryptography, namely Simplified DES, Simplified AES, RSA, Caesar Cipher, Monoalphabetic Cipher.
License
athlohangade/cryptography-algorithms
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Caesar Cipher is a type of substitution cipherin which each letter in the plaintext is replaced by a letter some fixed number of positions down thealphabetical order. Caesar cipher can be considered as a special case of monoalphabetic cipher. More informationavailablehere.
python3 caesar_cipher_encryption.py
python3 caesar_cipher_decryption.py
A monoalphabetic cipher is a substitution cipher in which the letters of the plaintext are mapped tociphertext letters based on a single alphabetic key. It is done by replacing the letters in plaintextwith the letters of ciphertext according to the key provided.More information availablehere
python3 monoalphabetic_cipher_encryption.py
python3 monoalphabetic_cipher_decryption.py
Data Encryption Standard (DES) is a symmetric-key algorithm for the encryption of digital data.DES is a block cipher - an algorithm that takes a fixed-length string of plaintext bits and transforms it through a series of complicated operations into another ciphertext bitstring of the same length.Simplified DES (SDES) was designed for educational purposes only, to help students learn the structure of DES using smaller blocks and keys.
Properties :
- It is aFeistel block cipher
- Plaintext : 8 bit
- Key : 10 bit
- Ciphertext : 8 bit
More informationhere
The programmain.py which is a driving program (to take input from user, call required functions and output the results) can be run to test the working of SDES.
python3 main.py
Also, the classSDES can be used in your program as follows.
Encryption :
fromSDESimportSDESplaintext="Hello World"key=167# Generate subkeys from the keysubkeys=SDES.generate_subkeys(key)# Encrypt the plaintext using the subkeysciphertext=SDES.encrypt(plaintext,subkeys)ciphertext="".join(ciphertext)print(ciphertext)# 1101001011000....110111101
Decryption :
fromSDESimportSDESciphertext="1101001011000....110111101"key=167# Generate subkeys from the keysubkeys=SDES.generate_subkeys(key)# Reverse the subkeys for decryptionsubkeys.reverse()# Decrypt the ciphertext using the subkeysplaintext=SDES.decrypt(ciphertext,subkeys)plaintext="".join(plaintext)print(plaintext)# Hello World
Advanced Encryption Standard (AES) is a symmetric key, block cipher algorithm used for encrypting digital data.Simplified AES (SAES) was designed for educational purposes only, to help students learn the structure of AES using smaller blocks and keys.
Properties :
- It is a non-feistel block cipher
- It is based onsubstitution-permutation network
- Plaintext : 16 bit
- Key : 16 bit
- Ciphertext : 16 bit
SAES structure :
Subkeys generation :
The programmain.py which is a driving program (to take input from user, call required functions and output the results) can be run to test the working of SAES.
python3 main.py
Also, the classSAES can be used in your program as follows.
Encryption :
fromSAESimportSAESplaintext="Hello World!"key=15476# Generate subkeys from the keysubkeys=SAES.generate_subkeys(key)# Encrypt the plaintext using the subkeysciphertext_blocks=SAES.encrypt(plaintext,subkeys)# Get in hexadecimal formatciphertext_hex= []foriinciphertext_blocks :ciphertext_hex.append("{:04X}".format(int(i,2)))print(ciphertext_hex)# ['2670', '78F3', '37A9', '138C', '296F', '0A9C']
Decryption :
fromSAESimportSAESciphertext_hex= ['2670','78F3','37A9','138C','296F','0A9C']key=15476# Generate subkeys from the keysubkeys=SAES.generate_subkeys(key)# Reverse the key pairwisesubkeys[0],subkeys[4]=subkeys[4],subkeys[0]subkeys[1],subkeys[5]=subkeys[5],subkeys[1]# Decrypt the ciphertext using the subkeysplaintext_blocks=SAES.decrypt(ciphertext_hex,subkeys)# Get the printable form of the decrypted plaintextplaintext= []foriinplaintext_blocks :plaintext.append(chr(int(i[:8],2)))plaintext.append(chr(int(i[8:],2)))plaintext="".join(plaintext)print(plaintext)# Hello World!
RSA (Rivest-Shamir-Adleman) is a public-key cryptosystem in which theencryption key is public and the decryption key is secret (private). An RSA user creates and publishes a public key based on two large prime numbers, along with an auxiliary value.The prime numbers are kept secret. Messages can be encrypted by anyone, via the public key, but can only be decoded by someone who knows the prime numbers. It is used for secure data transmission. More information availablehere
This repo demonstrates a simple implementation of RSA for educational purpose only.
The programmain.py which is a driving program (to take input from user, call required functions and output the results) can be run to test the working of RSA.
python3 main.py
Also, the classRSA can be used in your program as follows.
Encryption :
fromRSAimportRSAplaintext="Hello World"p,q=23,17# Perform encryption by passing required parametersciphertext=RSA.rsa_encryption(plaintext,p,q)print(ciphertext)# [353, 271, 105, 105, 155, 110, 9, 155, 367, 105, 348]
Decryption :
fromRSAimportRSAciphertext= [353,271,105,105,155,110,9,155,367,105,348]p,q=23,17# Perform decryption by passing required parametersplaintext=RSA.rsa_decryption(ciphertext,p,q)plaintext="".join(plaintext)print(plaintext)# Hello World
- Refer the documents under
docsfolder for more information and examples.
About
The repo is about simple implementation of various algorithms and techniques used in cryptography, namely Simplified DES, Simplified AES, RSA, Caesar Cipher, Monoalphabetic Cipher.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.










