Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NotificationsYou must be signed in to change notification settings

athlohangade/cryptography-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Theory

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.

Example

Usage

python3 caesar_cipher_encryption.py

Caesar Encryption

python3 caesar_cipher_decryption.py

Caesar Decryption


Monoalphabetic Cipher

Theory

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

Usage

python3 monoalphabetic_cipher_encryption.py

Monoalphabetic_Encryption

python3 monoalphabetic_cipher_decryption.py

Monoalphabetic_Decryption


Simplified DES

Theory

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 :

More informationhere

SDES structure

Usage

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

SDES example

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

Simplified AES

Theory

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 :

SAES structure

Subkeys generation :

Subkeys generation

Usage

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

SAES example

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

Theory

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.

Usage

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

RSA example

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

References

  • Refer the documents underdocs folder 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

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp