Spaces:
Sleeping
Sleeping
Ahmad Hammoudeh
commited on
Commit
·
4ac9f49
1
Parent(s):
1b93da3
Update msg_encX.py
Browse files- msg_encX.py +10 -8
msg_encX.py
CHANGED
|
@@ -9,11 +9,13 @@ from Crypto.Cipher import AES
|
|
| 9 |
import rsa
|
| 10 |
import string
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
def seedx(path , User_passcode=
|
| 17 |
try:
|
| 18 |
with open(path +'indx.txt') as f:
|
| 19 |
old_day_index = int(f.read())
|
|
@@ -46,7 +48,7 @@ def seedx(path , User_passcode=int(os.environ['User_passcode']), N_days=int(os.e
|
|
| 46 |
return {'seed':seed,'publicKey': publicKey, 'privateKey': privateKey}
|
| 47 |
|
| 48 |
|
| 49 |
-
def AES_encrypt(User_message,seed, publicKey,encoding =
|
| 50 |
#number conversion to encrypt non-english content
|
| 51 |
User_message_numbered = (int.from_bytes(bytes(User_message, 'utf-16'), "big"))
|
| 52 |
#padding
|
|
@@ -93,7 +95,7 @@ class AESCipher(object):
|
|
| 93 |
def invert_perm_list(p):
|
| 94 |
return [p.index(l) for l in range(len(p))]
|
| 95 |
|
| 96 |
-
def AES_decrypt(encMessage,seed,publicKey, encoding =
|
| 97 |
if encoding == 0:
|
| 98 |
encMessage_byte = encMessage
|
| 99 |
elif encoding == 1:
|
|
@@ -117,7 +119,7 @@ def AES_decrypt(encMessage,seed,publicKey, encoding = 1, encryption_difficulty =
|
|
| 117 |
def Encrypt_msg(User_message,user_password,path):
|
| 118 |
User_passcode = (int.from_bytes(bytes(str(user_password), 'utf-8'), "little"))
|
| 119 |
Num_dict_enc = seedx(path, User_passcode)
|
| 120 |
-
encMessage_i = AES_encrypt(User_message,Num_dict_enc['seed'], Num_dict_enc['publicKey'],encoding =
|
| 121 |
#print(encMessage_i)
|
| 122 |
return encMessage_i
|
| 123 |
|
|
@@ -125,6 +127,6 @@ def Encrypt_msg(User_message,user_password,path):
|
|
| 125 |
def Decrypt_msg(encMessage,user_password,path):
|
| 126 |
User_passcode = (int.from_bytes(bytes(str(user_password), 'utf-8'), "little"))
|
| 127 |
Num_dict_enc = seedx(path, User_passcode)
|
| 128 |
-
recovered_msg = AES_decrypt(encMessage,Num_dict_enc['seed'], Num_dict_enc['publicKey'], encoding =
|
| 129 |
#print(recovered_msg)
|
| 130 |
return recovered_msg
|
|
|
|
| 9 |
import rsa
|
| 10 |
import string
|
| 11 |
|
| 12 |
+
encoding0 = int(os.environ['encoding'])
|
| 13 |
+
padding0 = int(os.environ['padding'])
|
| 14 |
+
encryption_difficulty0 = int(os.environ['encryption_difficulty'])
|
| 15 |
+
N_days0=int(os.environ['N_days'])
|
| 16 |
+
User_passcode0=int(os.environ['User_passcode'])
|
| 17 |
|
| 18 |
+
def seedx(path , User_passcode=User_passcode0, N_days=N_days0, encryption_difficulty = encryption_difficulty0):
|
| 19 |
try:
|
| 20 |
with open(path +'indx.txt') as f:
|
| 21 |
old_day_index = int(f.read())
|
|
|
|
| 48 |
return {'seed':seed,'publicKey': publicKey, 'privateKey': privateKey}
|
| 49 |
|
| 50 |
|
| 51 |
+
def AES_encrypt(User_message,seed, publicKey,encoding = encoding0, padding = padding0):
|
| 52 |
#number conversion to encrypt non-english content
|
| 53 |
User_message_numbered = (int.from_bytes(bytes(User_message, 'utf-16'), "big"))
|
| 54 |
#padding
|
|
|
|
| 95 |
def invert_perm_list(p):
|
| 96 |
return [p.index(l) for l in range(len(p))]
|
| 97 |
|
| 98 |
+
def AES_decrypt(encMessage,seed,publicKey, encoding = encoding0, encryption_difficulty = encryption_difficulty0, padding = padding0):
|
| 99 |
if encoding == 0:
|
| 100 |
encMessage_byte = encMessage
|
| 101 |
elif encoding == 1:
|
|
|
|
| 119 |
def Encrypt_msg(User_message,user_password,path):
|
| 120 |
User_passcode = (int.from_bytes(bytes(str(user_password), 'utf-8'), "little"))
|
| 121 |
Num_dict_enc = seedx(path, User_passcode)
|
| 122 |
+
encMessage_i = AES_encrypt(User_message,Num_dict_enc['seed'], Num_dict_enc['publicKey'],encoding = encoding0, padding = padding0)
|
| 123 |
#print(encMessage_i)
|
| 124 |
return encMessage_i
|
| 125 |
|
|
|
|
| 127 |
def Decrypt_msg(encMessage,user_password,path):
|
| 128 |
User_passcode = (int.from_bytes(bytes(str(user_password), 'utf-8'), "little"))
|
| 129 |
Num_dict_enc = seedx(path, User_passcode)
|
| 130 |
+
recovered_msg = AES_decrypt(encMessage,Num_dict_enc['seed'], Num_dict_enc['publicKey'], encoding = encoding0, encryption_difficulty = encryption_difficulty0, padding = padding0)
|
| 131 |
#print(recovered_msg)
|
| 132 |
return recovered_msg
|