├── Ceaser_Cipher_Code.py ├── LICENSE ├── README.md ├── RSA_Calculations_Code.py ├── RSA_Encryption_Decryption_Code.py ├── Substitution_Cipher_Code.py └── Vignere Cipher.py /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Encryption-And-Decryption-Programs 2 | Ciphers and Encryption Apps 3 | This repository contains various ciphers and encryption applications implemented in Python. 4 | 5 | Table of Contents 6 | Description 7 | Installation 8 | Usage 9 | Contributing 10 | License 11 | Description 12 | 13 | 14 | 15 | This repository contains a collection of ciphers and encryption applications implemented in Python. The ciphers include classic ciphers like Caesar Cipher, Vigenere Cipher, Playfair Cipher, etc. The encryption applications include tools for encryption and decryption of messages, password generators, and more. 16 | 17 | Installation 18 | To use the code in this repository, you need to have Python 3 installed on your machine. You can download and install the latest version of Python from the official website https://www.python.org/downloads/. 19 | 20 | Once you have installed Python, you can clone this repository to your local machine using the following command: 21 | 22 | git clone https://github.com/alok-2002/Encryption-And-Decryption-Programs.git 23 | 24 | 25 | After cloning the repository, you need to install the required Python packages. You can do this by running the following command in the repository directory: 26 | 27 | pip install -r requirements.txt 28 | 29 | Usage 30 | To use the ciphers and encryption applications in this repository, simply run the Python files in the src directory. Each file corresponds to a different cipher or encryption application. 31 | 32 | For example, to encrypt a message using the Caesar Cipher, you can run the following command: 33 | 34 | python src/caesar_cipher.py -e "hello world" -k 3 35 | 36 | This will encrypt the message "hello world" using the Caesar Cipher with a key of 3. You can find more information about the available options for each cipher or encryption application by running it with the -h or --help option. 37 | 38 | 39 | Contributing 40 | If you would like to contribute to this repository, please feel free to fork the repository and submit a pull request. You can also open an issue if you find a bug or have a suggestion for a new cipher or encryption application. 41 | 42 | License 43 | This repository is licensed under the MIT license. See License for more information. 44 | 45 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------