Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,7 +74,7 @@ def generate_keys1():
|
|
| 74 |
def encrypt_text1(data,in2,address):
|
| 75 |
data = data.encode("utf-8")
|
| 76 |
#data = "I met aliens in UFO. Here is the map.".encode("utf-8")
|
| 77 |
-
file_out = open("encrypted_data.bin", "wb")
|
| 78 |
|
| 79 |
recipient_key = RSA.import_key(open("receiver.pem").read())
|
| 80 |
session_key = get_random_bytes(16)
|
|
@@ -86,11 +86,11 @@ def encrypt_text1(data,in2,address):
|
|
| 86 |
# Encrypt the data with the AES session key
|
| 87 |
cipher_aes = AES.new(session_key, AES.MODE_EAX)
|
| 88 |
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
|
| 89 |
-
[ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ]
|
| 90 |
-
file_out.close()
|
| 91 |
|
| 92 |
|
| 93 |
-
out_string = f'{enc_session_key}+
|
| 94 |
|
| 95 |
#output=open("encrypted_data.bin", "rb")
|
| 96 |
|
|
@@ -102,14 +102,37 @@ def encrypt_text1(data,in2,address):
|
|
| 102 |
#output.close()
|
| 103 |
return str(out_string),enc_qr
|
| 104 |
|
| 105 |
-
def decrypt_text1(
|
| 106 |
-
#in1= in1.encode("utf-8")
|
| 107 |
-
#file_out = open("encrypted_data2.bin","wb")
|
| 108 |
-
#[ file_out.write(x) for x in (in1.enc_session_key, in1.cipher_aes.nonce, in1.tag, in1.ciphertext) ]
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
file_in = open("encrypted_data.bin", "rb")
|
| 114 |
|
| 115 |
private_key = RSA.import_key(open("private.pem").read())
|
|
|
|
| 74 |
def encrypt_text1(data,in2,address):
|
| 75 |
data = data.encode("utf-8")
|
| 76 |
#data = "I met aliens in UFO. Here is the map.".encode("utf-8")
|
| 77 |
+
#file_out = open("encrypted_data.bin", "wb")
|
| 78 |
|
| 79 |
recipient_key = RSA.import_key(open("receiver.pem").read())
|
| 80 |
session_key = get_random_bytes(16)
|
|
|
|
| 86 |
# Encrypt the data with the AES session key
|
| 87 |
cipher_aes = AES.new(session_key, AES.MODE_EAX)
|
| 88 |
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
|
| 89 |
+
#[ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ]
|
| 90 |
+
#file_out.close()
|
| 91 |
|
| 92 |
|
| 93 |
+
out_string = f'{enc_session_key}+aaa+{cipher_aes.nonce}+bbb+{tag}+ccc+{ciphertext}+ddd+'
|
| 94 |
|
| 95 |
#output=open("encrypted_data.bin", "rb")
|
| 96 |
|
|
|
|
| 102 |
#output.close()
|
| 103 |
return str(out_string),enc_qr
|
| 104 |
|
| 105 |
+
def decrypt_text1(im,in2):
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
enc_in = stegan.decode(im)
|
| 108 |
+
if "+aaa+" in enc_in:
|
| 109 |
+
mes1=enc_in.split("+aaa+",1)[0]
|
| 110 |
+
mes1=mes1.strip("b'").strip("'")
|
| 111 |
+
mes_bytes = bytes(mes1,'utf-8')
|
| 112 |
+
#mes_dec = fernet.decrypt(mes_bytes).decode()
|
| 113 |
+
if "+bbb+" in decode_qr:
|
| 114 |
+
mes2=enc_in.split("+aaa+",1)[1]
|
| 115 |
+
mes2=mes2.split("+bbb+",1)[0]
|
| 116 |
+
mes2=mes2.strip("b'").strip("'")
|
| 117 |
+
mes_bytes2 = bytes(mes2,'utf-8')
|
| 118 |
+
if "+ccc+" in decode_qr:
|
| 119 |
+
mes3=enc_in.split("+bbb+",1)[1]
|
| 120 |
+
mes3=mes3.split("+bbb+",1)[0]
|
| 121 |
+
mes3=mes3.strip("b'").strip("'")
|
| 122 |
+
mes_bytes3 = bytes(mes3,'utf-8')
|
| 123 |
+
if "+ddd+" in decode_qr:
|
| 124 |
+
mes4=enc_in.split("+ccc+",1)[1]
|
| 125 |
+
mes4=mes4.split("+ddd+",1)[0]
|
| 126 |
+
mes4=mes4.strip("b'").strip("'")
|
| 127 |
+
mes_bytes4 = bytes(mes4,'utf-8')
|
| 128 |
+
|
| 129 |
+
file_out = open("encrypted_data.bin", "wb")
|
| 130 |
+
[ file_out.write(x) for x in (mes1, mes2, mes3, mes4) ]
|
| 131 |
+
file_out.close()
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
|
| 136 |
file_in = open("encrypted_data.bin", "rb")
|
| 137 |
|
| 138 |
private_key = RSA.import_key(open("private.pem").read())
|