From 52ccbc6e05e165a4eabe3a50b610c27d2e30bc7f Mon Sep 17 00:00:00 2001 From: Swapnanil Ray <67406959+redhatpanda@users.noreply.github.com> Date: Sun, 3 Oct 2021 13:11:16 +0530 Subject: [PATCH 1/2] Added a 2step text encryption module --- .../AES Encryption Template/aes.py | 36 ++++++++++++++++++ .../__pycache__/decrypt.cpython-38.pyc | Bin 0 -> 386 bytes .../__pycache__/encrypt.cpython-38.pyc | Bin 0 -> 380 bytes Projects/Encryption Module(2 Step)/decrypt.py | 6 +++ Projects/Encryption Module(2 Step)/encrypt.py | 6 +++ Projects/Encryption Module(2 Step)/test.py | 10 +++++ 6 files changed, 58 insertions(+) create mode 100644 Projects/Encryption Module(2 Step)/AES Encryption Template/aes.py create mode 100644 Projects/Encryption Module(2 Step)/__pycache__/decrypt.cpython-38.pyc create mode 100644 Projects/Encryption Module(2 Step)/__pycache__/encrypt.cpython-38.pyc create mode 100644 Projects/Encryption Module(2 Step)/decrypt.py create mode 100644 Projects/Encryption Module(2 Step)/encrypt.py create mode 100644 Projects/Encryption Module(2 Step)/test.py 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 0000000000000000000000000000000000000000..9edc8625ed39ae9b82e6cc642bf5aa25dfe1c780 GIT binary patch literal 386 zcmYjN%}T>S5Z>Jsn-+^6e1JVR2Ymn$u{14~Y82C4!h(eCQe&HB*^NRV-n{t|?a^1- zs|WEFyyzrG=)lZ;-_HLAgFzpG{CplnZ{R;_vMU701*kp(!x6`86e3Qz^@>8wv5%b2 z7etU3*O~uf0qB5^L7U0~ZE%Guyd@j5MK7cxP>DUqGM3Vj>2eXPQWjPo~pRzy;rP+KoTQFDXRgp_}JGt|3ywMf)7r}H& zhk@i#A!w4(OV@SS_#rCjNJ=_Pqa^#|$H3VnYbGaoMz3@Jv=*$Lcp^*FZ*i)Z^^Lkd h65&Ivdf*+R>Q88Jv)YcaAz literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..13e54e2ec84c0c444d899b2dedd957a31f3bc776 GIT binary patch literal 380 zcmYjNy-ve05VoC)q?IZdcmR*h01to=qH0=E0RfR_sVt!oTP3tftT-JarDEYh+L2fC z$^x&z#5oO8Px{W^=lk)U!+yVqz?|>n=pD{4BMyy#xCW?Ga2#>GLUY6kw?5Dua~vSI z^8*p&$0qaNEFc}g2+&lPXp3vKB|B8(9odkYKqdBFOIwACv@No@sAQ>+faF}jy`2iB zqJ_}5T)#XoMWwrKlHi}HaG>+=TYSMnB?`rEr_&kpgj$xlWRK&g;K3i>(O?!%CUg)= z9+iS78NKm5myKSdk`AS$gEUIAy*>lY#`__XJfrtHU#|pfUp$wU?zKEs3$vXv>mhuC e3-f<2Da`r}Z$>+CT?lCBGHp6uVNlBCI^+-Zg Date: Sun, 3 Oct 2021 13:12:26 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)