├── LICENSE ├── RSA_Encryption_Decryption_Code.py ├── Vignere Cipher.py ├── Substitution_Cipher_Code.py ├── RSA_Calculations_Code.py ├── Ceaser_Cipher_Code.py └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Alok Sharma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RSA_Encryption_Decryption_Code.py: -------------------------------------------------------------------------------- 1 | import random 2 | import math 3 | 4 | def gcd(a, b): 5 | while b != 0: 6 | a, b = b, a % b 7 | return a 8 | 9 | def multiplicative_inverse(e, phi): 10 | def extended_gcd(a, b): 11 | if b == 0: 12 | return (a, 1, 0) 13 | else: 14 | gcd, x, y = extended_gcd(b, a % b) 15 | return (gcd, y, x - (a // b) * y) 16 | gcd, x, y = extended_gcd(e, phi) 17 | if gcd != 1: 18 | return None 19 | else: 20 | return x % phi 21 | 22 | def generate_keypair(p, q): 23 | n = p * q 24 | phi = (p - 1) * (q - 1) 25 | e = random.randrange(1, phi) 26 | g = gcd(e, phi) 27 | while g != 1: 28 | e = random.randrange(1, phi) 29 | g = gcd(e, phi) 30 | d = multiplicative_inverse(e, phi) 31 | return ((e, n), (d, n)) 32 | 33 | def encrypt(public_key, plaintext): 34 | e, n = public_key 35 | cipher = [(ord(char) ** e) % n for char in plaintext] 36 | return cipher 37 | 38 | def decrypt(private_key, ciphertext): 39 | d, n = private_key 40 | plain = [chr((char ** d) % n) for char in ciphertext] 41 | return ''.join(plain) 42 | 43 | public_key,private_key = generate_keypair(7,11) 44 | 45 | message = input("Enter The Message: ") 46 | print("Original Message is: ",message) 47 | 48 | cipher = encrypt(public_key,message) 49 | print("Encrypted Message: ",cipher) 50 | 51 | plain = decrypt(private_key,cipher) 52 | print("Decrypted Message: ",plain) 53 | -------------------------------------------------------------------------------- /Vignere Cipher.py: -------------------------------------------------------------------------------- 1 | def encrypt(plaintext, key): 2 | encrypted_text = "" 3 | key_length = len(key) 4 | for i, char in enumerate(plaintext): 5 | if char.isalpha(): 6 | key_shift = ord(key[i % key_length].upper()) - ord('A') 7 | if char.isupper(): 8 | encrypted_char = chr((ord(char) - ord('A') + key_shift) % 26 + ord('A')) 9 | else: 10 | encrypted_char = chr((ord(char) - ord('a') + key_shift) % 26 + ord('a')) 11 | encrypted_text += encrypted_char 12 | else: 13 | encrypted_text += char 14 | return encrypted_text 15 | 16 | def decrypt(ciphertext, key): 17 | decrypted_text = "" 18 | key_length = len(key) 19 | for i, char in enumerate(ciphertext): 20 | if char.isalpha(): 21 | key_shift = ord(key[i % key_length].upper()) - ord('A') 22 | if char.isupper(): 23 | decrypted_char = chr((ord(char) - ord('A') - key_shift) % 26 + ord('A')) 24 | else: 25 | decrypted_char = chr((ord(char) - ord('a') - key_shift) % 26 + ord('a')) 26 | decrypted_text += decrypted_char 27 | else: 28 | decrypted_text += char 29 | return decrypted_text 30 | 31 | plaintext = "Hello, World" 32 | key = "KEY" 33 | 34 | encrypted_text = encrypt(plaintext, key) 35 | print("Encrypted text:", encrypted_text) 36 | 37 | decrypted_text = decrypt(encrypted_text, key) 38 | print("Decrypted text:", decrypted_text) 39 | -------------------------------------------------------------------------------- /Substitution_Cipher_Code.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | characters = " " +"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/*!~@#$%^&()|\/<>:;" 4 | characters = list(characters) 5 | key = characters.copy() 6 | random.shuffle(key) 7 | # print(key) 8 | 9 | #Encryption Process 10 | def Encryption(): 11 | plain_text = input("Enter The Message To Encrypt : ") 12 | cipher_text = " " 13 | 14 | for letter in plain_text: 15 | index = characters.index(letter) 16 | cipher_text += key[index] 17 | 18 | print("Original Message is :",plain_text) 19 | print("Encrypted Message is :",cipher_text) 20 | 21 | return 22 | 23 | #Decryption Process 24 | def Decryption(): 25 | cipher_text = input("Enter The Message To Decrypt : ") 26 | plain_text = " " 27 | 28 | 29 | for letter in cipher_text: 30 | index = key.index(letter) 31 | plain_text += characters[index] 32 | 33 | print("Original Message is :",plain_text) 34 | return 35 | 36 | def Substitution_Cipher(): 37 | while True: 38 | user_input = input('''"What Do You Want To Do? 39 | 1.Encryption 40 | 2.Decryption 41 | 3.Exit : ''') 42 | 43 | if user_input == "1": 44 | print("******YOU HAVE SELECTED ENCRYPTION PROCESS*****") 45 | Encryption() 46 | elif user_input == "2": 47 | print("******YOU HAVE SELECTED DECRYPTION PROCESS*****") 48 | Decryption() 49 | else: 50 | print("Exiting...........") 51 | break 52 | 53 | 54 | Substitution_Cipher() 55 | -------------------------------------------------------------------------------- /RSA_Calculations_Code.py: -------------------------------------------------------------------------------- 1 | import random 2 | import math 3 | 4 | def generate_p_and_q(): 5 | 6 | p = int(input("Enter The Value Of P: ")) 7 | q = int(input("Enter The Value OF Q: ")) 8 | 9 | return p, q 10 | 11 | p,q = generate_p_and_q() 12 | 13 | n = p * q 14 | P = p -1 15 | Q = q -1 16 | 17 | phi = (P*Q) 18 | print("Value Of N is = ",n,"\nAnd Value Of Φ(N) = ",phi) 19 | 20 | def generate_e(phi): 21 | possible_e_values = [] 22 | 23 | for i in range(2,phi): 24 | if math.gcd(i,phi) == 1: 25 | e=i 26 | possible_e_values.append(e) 27 | 28 | # print("The All Possible Values Are : ",possible_e_values) 29 | 30 | return random.choice(possible_e_values) 31 | 32 | e = generate_e(phi) 33 | 34 | print("Value Of E is = ",e) 35 | 36 | 37 | def generate_d(e,phi): 38 | 39 | # d_list = [] 40 | 41 | for i in range(2,phi): 42 | 43 | if (i*e) % phi == 1: 44 | d = i 45 | # d_list.append(d) 46 | break 47 | 48 | # print(d_list) 49 | return d 50 | 51 | d = generate_d(e,phi) 52 | 53 | print("Value of D is = ",d) 54 | 55 | message = random.randint(1,n) 56 | 57 | print("Random Generated Message is : ",message) 58 | 59 | def encrypt(message,e,n): 60 | c = pow(message,e,n) 61 | return c 62 | 63 | Encrypted_Message = encrypt(message,e,n) 64 | 65 | print("Encrypted message is : ",Encrypted_Message) 66 | 67 | def decrypt(message,d,n): 68 | p = pow(message,d,n) 69 | return p 70 | 71 | Decrypted_message = decrypt(Encrypted_Message,d,n) 72 | print("Decrypted Message is : ",Decrypted_message) 73 | -------------------------------------------------------------------------------- /Ceaser_Cipher_Code.py: -------------------------------------------------------------------------------- 1 | alphabets = "abcdefghijklmnopqrstuvwxyz" 2 | numberofletters = len(alphabets) 3 | print("*******CEASER CIPHER*******") 4 | def Encrypt(Plain_Text ,Key): 5 | Cipher_Text = '' 6 | for letter in Plain_Text : 7 | letter = letter.lower() 8 | if not letter == ' ': 9 | Index = alphabets.find(letter) 10 | if Index == -1: 11 | Cipher_Text += letter 12 | else: 13 | New_Index =Index + key 14 | if New_Index >= numberofletters: 15 | New_Index -= numberofletters 16 | Cipher_Text += alphabets[New_Index] 17 | return Cipher_Text 18 | 19 | 20 | def Decrypt(Cipher_Text ,Key): 21 | Plain_Text = '' 22 | for letter in Cipher_Text : 23 | letter = letter.lower() 24 | if not letter == ' ': 25 | Index = alphabets.find(letter) 26 | if Index == -1: 27 | Plain_Text += letter 28 | else: 29 | New_Index =Index + key 30 | if New_Index < 0: 31 | New_Index += numberofletters 32 | Plain_Text += alphabets[New_Index] 33 | return Plain_Text 34 | 35 | 36 | while True: 37 | user_input = input('''What Do You Want To Do ? 38 | 1.Perform Encryption 39 | 2.Perform Decryption 40 | 3.Press 0 To Exit ''').upper() 41 | 42 | if user_input == "1": 43 | print("\n----You've Selected The Option To Encrypt The Plain Text Into Cipher Text----\n") 44 | key = int(input("Enter The Key Between 1 To 26: ")) 45 | text = input("Enter The Plain Text That You Want To Encrypt: ") 46 | Cipher_Text = Encrypt(text,key) 47 | print(f'Your Encrypted Cipher Text is: {Cipher_Text}') 48 | 49 | elif user_input == "2": 50 | print("\n----You've Selected The Option To Decrypt The Cipher Text Into Original Plain Text----\n") 51 | key = int(input("Enter The Key Between 1 To 26: ")) 52 | text = input("Enter The Plain Text That You Want To Decrypt: ") 53 | Plain_Text = Decrypt(text,key) 54 | print(f'Your Decrypted Plain Text is: {Plain_Text}') 55 | else: 56 | print("Exiting.....") 57 | break 58 | 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔒 Encryption & Decryption Programs 2 | 3 | ![Python](https://img.shields.io/badge/Python-3.x-blue?logo=python) 4 | ![MIT License](https://img.shields.io/badge/License-MIT-green.svg) 5 | ![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103) 6 | ![GitHub repo size](https://img.shields.io/github/repo-size/alok-2002/Encryption-And-Decryption-Programs) 7 | ![GitHub stars](https://img.shields.io/github/stars/alok-2002/Encryption-And-Decryption-Programs?style=social) 8 | ![Last Commit](https://img.shields.io/github/last-commit/alok-2002/Encryption-And-Decryption-Programs) 9 | ![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat) 10 | 11 | > ✏️ A curated collection of classic ciphers & encryption utilities built in Python. 12 | 13 | --- 14 | 15 | ## 📌 Table of Contents 16 | - [📄 Overview](#-overview) 17 | - [⚙️ Installation](#️-installation) 18 | - [🚀 Usage](#-usage) 19 | - [🤝 Contributing](#-contributing) 20 | - [📝 License](#-license) 21 | 22 | --- 23 | 24 | ## 📄 Overview 25 | 26 | This repository features a variety of encryption and decryption tools implemented in Python. 27 | Included are classic ciphers such as: 28 | - **Caesar Cipher** 29 | - **Vigenère Cipher** 30 | - **Playfair Cipher** 31 | ...and more! 32 | 33 | Additionally, it offers: 34 | - Command-line tools to encrypt & decrypt messages 35 | - Simple password generators 36 | - Utility scripts to experiment with cryptography basics 37 | 38 | Ideal for beginners and enthusiasts exploring encryption fundamentals. 39 | 40 | --- 41 | 42 | ## ⚙️ Installation 43 | 44 | 1️⃣ **Ensure you have Python 3.x installed** 45 | 👉 Download from: [python.org/downloads](https://www.python.org/downloads/) 46 | 47 | 2️⃣ **Clone this repository:** 48 | ```bash 49 | git clone https://github.com/alok-2002/Encryption-And-Decryption-Programs.git 50 | ```` 51 | 52 | 3️⃣ **Install dependencies:** 53 | 54 | ```bash 55 | cd Encryption-And-Decryption-Programs 56 | pip install -r requirements.txt 57 | ``` 58 | 59 | --- 60 | 61 | ## 🚀 Usage 62 | 63 | Navigate to the `src` directory and run the desired script. 64 | 65 | Example: Encrypting a message using Caesar Cipher: 66 | 67 | ```bash 68 | python src/caesar_cipher.py -e "hello world" -k 3 69 | ``` 70 | 71 | * `-e` : Encrypt the message 72 | * `-k` : Key for shifting characters 73 | 74 | To see all options for a cipher or tool: 75 | 76 | ```bash 77 | python src/caesar_cipher.py -h 78 | ``` 79 | 80 | --- 81 | 82 | ## 🤝 Contributing 83 | 84 | Contributions are warmly welcomed! 🌟 85 | 86 | * Fork the repository 87 | * Create a feature branch 88 | * Commit your changes 89 | * Open a pull request 90 | 91 | You can also open issues for bugs, improvements, or suggestions for new ciphers and tools. 92 | 93 | --- 94 | 95 | ## 📝 License 96 | 97 | This project is licensed under the [MIT License](LICENSE). 98 | 99 | --- 100 | 101 | ### ⭐ Star this repository to support the project and stay updated! 102 | --------------------------------------------------------------------------------