-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegenerator.py
More file actions
44 lines (31 loc) · 1.17 KB
/
Copy pathcodegenerator.py
File metadata and controls
44 lines (31 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import random
from Cryptodome.Cipher import AES
from binascii import b2a_hex, a2b_hex
class Verfication:
def generate_code(self):
num = random.randint(100,999)
cap1 = chr(random.randint(65,90))
cap2 = chr(random.randint(65,90))
low = chr(random.randint(97,122))
vercode = cap1 + str(num) + cap2 + low
return vercode
class Encryption():
def __init__(self):
self.key = 'keyskeyskeyskeys'
def encrypt_Code(self, text):
cryptor = AES.new(self.key.encode("utf8"), AES.MODE_CBC, b'0000000000000000')
length = 16
count = len(text)
if count < length:
add = (length - count)
# \0 backspace
text = text + ('\0' * add)
elif count > length:
add = (length - (count % length))
text = text + ('\0' * add)
self.ciphertext = cryptor.encrypt(text.encode("utf8"))
return b2a_hex(self.ciphertext)
def decrpty_Code(self, text):
cryptor = AES.new(self.key.encode("utf8"), AES.MODE_CBC, b'0000000000000000')
plain_text = cryptor.decrypt(a2b_hex(text)).decode()
return plain_text.rstrip('\0')