Delete encryption.py
Browse files- encryption.py +0 -33
encryption.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
from Crypto.Cipher import AES
|
| 2 |
-
from Crypto.Util.Padding import pad, unpad
|
| 3 |
-
from base64 import b64encode , urlsafe_b64decode
|
| 4 |
-
|
| 5 |
-
class encryption:
|
| 6 |
-
def __init__(self, auth,):
|
| 7 |
-
self.key = bytearray(self.secret(auth), "UTF-8")
|
| 8 |
-
self.iv = bytearray.fromhex('00000000000000000000000000000000')
|
| 9 |
-
|
| 10 |
-
def replaceCharAt(self, e, t, i):
|
| 11 |
-
return e[0:t] + i + e[t + len(i):]
|
| 12 |
-
|
| 13 |
-
def secret(self, e):
|
| 14 |
-
t = e[0:8]
|
| 15 |
-
i = e[8:16]
|
| 16 |
-
n = e[16:24] + t + e[24:32] + i
|
| 17 |
-
s = 0
|
| 18 |
-
while(s < len(n)):
|
| 19 |
-
e = n[s]
|
| 20 |
-
if e >= '0' and e <= '9':
|
| 21 |
-
t = chr((ord(e[0]) - ord('0') + 5) % 10 + ord('0'))
|
| 22 |
-
n = self.replaceCharAt(n, s, t)
|
| 23 |
-
else:
|
| 24 |
-
t = chr((ord(e[0]) - ord('a') + 9) % 26 + ord('a'))
|
| 25 |
-
n = self.replaceCharAt(n, s, t)
|
| 26 |
-
s += 1
|
| 27 |
-
return n
|
| 28 |
-
|
| 29 |
-
def encrypt(self, text):
|
| 30 |
-
return b64encode(AES.new(self.key, AES.MODE_CBC, self.iv).encrypt(pad(text.encode('UTF-8'), AES.block_size))).decode('UTF-8')
|
| 31 |
-
|
| 32 |
-
def decrypt(self, text):
|
| 33 |
-
return unpad(AES.new(self.key, AES.MODE_CBC, self.iv).decrypt(urlsafe_b64decode(text.encode('UTF-8'))), AES.block_size).decode('UTF-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|