diff --git a/Projects/Encryption Module(2 Step)/AES Encryption Template/aes.py b/Projects/Encryption Module(2 Step)/AES Encryption Template/aes.py new file mode 100644 index 0000000..eab5653 --- /dev/null +++ b/Projects/Encryption Module(2 Step)/AES Encryption Template/aes.py @@ -0,0 +1,36 @@ +import rsa +import rsa.randnum +import random +from Crypto.Cipher import AES +from secrets import token_bytes + +key = rsa.randnum.read_random_bits(128) #Generate a Random Key +pub_key,prvt_key = rsa.newkeys(512) #Generate Public & Private Keys for RSA Encryption +encrypted_aes_key = rsa.encrypt(key, pub_key) #Encrypt the Random Key using RSA + +def encrypt(msg): #Sending End + cipher = AES.new(key,AES.MODE_EAX) #Using the Random Key, encrypt the data using AES + nonce = cipher.nonce + ciphertext,tag = cipher.encrypt_and_digest(msg.encode('ascii')) #Encode the Data to ASCII, since AES takes only Bytes + return nonce, ciphertext, tag + +#Send the Encrypted Data, along with the Encrypted Random Key (RSA Encrypted) +def decrypt(nonce,ciphertext,tag): #Receiving End + aes_key = rsa.decrypt(encrypted_aes_key,prvt_key) #Decrypt the Key using RSA + cipher = AES.new(aes_key, AES.MODE_EAX, nonce=nonce) #Use the above key to decrypt the Data. + plaintext = cipher.decrypt(ciphertext) + try: + cipher.verify(tag) + return plaintext.decode('ascii') #Decode the text from ASCII to String + except: + return False + + + +nonce,ciphertext,tag = encrypt(input("Enter a message: ")) +plaintext = decrypt(nonce,ciphertext,tag) +print(f'Cipher text: {ciphertext}') +if not plaintext: + print('Message is Corrupted') +else: + print(f'Plain Text: {plaintext}') \ No newline at end of file diff --git a/Projects/Encryption Module(2 Step)/__pycache__/decrypt.cpython-38.pyc b/Projects/Encryption Module(2 Step)/__pycache__/decrypt.cpython-38.pyc new file mode 100644 index 0000000..9edc862 Binary files /dev/null and b/Projects/Encryption Module(2 Step)/__pycache__/decrypt.cpython-38.pyc differ diff --git a/Projects/Encryption Module(2 Step)/__pycache__/encrypt.cpython-38.pyc b/Projects/Encryption Module(2 Step)/__pycache__/encrypt.cpython-38.pyc new file mode 100644 index 0000000..13e54e2 Binary files /dev/null and b/Projects/Encryption Module(2 Step)/__pycache__/encrypt.cpython-38.pyc differ diff --git a/Projects/Encryption Module(2 Step)/decrypt.py b/Projects/Encryption Module(2 Step)/decrypt.py new file mode 100644 index 0000000..a9e9ce8 --- /dev/null +++ b/Projects/Encryption Module(2 Step)/decrypt.py @@ -0,0 +1,6 @@ +import rsa + +def decryptmsg(cryptmessage,prvt_key): + decrypted = rsa.decrypt(cryptmessage,prvt_key).decode() + return decrypted + diff --git a/Projects/Encryption Module(2 Step)/encrypt.py b/Projects/Encryption Module(2 Step)/encrypt.py new file mode 100644 index 0000000..3586221 --- /dev/null +++ b/Projects/Encryption Module(2 Step)/encrypt.py @@ -0,0 +1,6 @@ +import rsa + +def encryptmsg(message,pub_key): + encrypted = rsa.encrypt(message.encode(),pub_key) + return encrypted + diff --git a/Projects/Encryption Module(2 Step)/test.py b/Projects/Encryption Module(2 Step)/test.py new file mode 100644 index 0000000..f6551a7 --- /dev/null +++ b/Projects/Encryption Module(2 Step)/test.py @@ -0,0 +1,10 @@ +import rsa +import encrypt +import decrypt + +message = input("Enter a message to be encrypted:") +pub_key,prvt_key = rsa.newkeys(512) +res = encrypt.encryptmsg(message,pub_key) +unres = decrypt.decryptmsg(res,prvt_key) +print("Encrypted Message: ",res) +print("Decrypted Message: ",unres) \ No newline at end of file diff --git a/README.md b/README.md index 8a11ee4..ee2015f 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ After contributing add your **NAME and USER NAME** here: 5. **Mohit** - [MohitOnHub](https://github.com/MohitOnHub) 6. **Vikalp Shishodia** - [VkRan](https://github.com/VkRan) - 7. **Full Name** - [User Name](https://github.com/username) + 7. **Swapnanil Ray** - [redhatpanda](https://github.com/redhatpanda) 8. **Full Name** - [User Name](https://github.com/username)