2
2
import pathlib
3
3
import os
4
4
import re
5
+ import string
5
6
from pathlib import Path
6
7
7
8
@@ -16,12 +17,32 @@ def relative_to_assets(path: str) -> Path:
16
17
return API_PATH / Path (path )
17
18
18
19
20
+ shiftAlpha = 4
19
21
API_CONTENT = None
20
22
# π Security execution READ
21
23
22
24
23
25
def API_SEC ():
24
26
global API_CONTENT
27
+ global shiftAlpha
28
+
29
+ # Caesar Cipher
30
+ alphaCharset = string .ascii_letters
31
+ numCharset = string .digits
32
+ charsetMain = alphaCharset + numCharset
33
+
34
+ totalNum = 0
35
+ for i in range (len (charsetMain )):
36
+ totalNum += i
37
+
38
+ shiftAlpha %= totalNum
39
+
40
+ unshiftAlpha = - shiftAlpha
41
+
42
+ alphaUnshifted = None
43
+ alphaUnshifted = charsetMain [unshiftAlpha :] + charsetMain [:unshiftAlpha ]
44
+ tableContentUn = str .maketrans (charsetMain , alphaUnshifted )
45
+
25
46
# Security measures
26
47
API_CONTENT = open (relative_to_assets ("Data/security/API" ), "r" ).read ()
27
48
API_DECODED = base64 .b64decode (API_CONTENT .encode ("utf-8" ))
@@ -30,14 +51,36 @@ def API_SEC():
30
51
API_DECODED_CLEAN = re .sub (
31
52
r"[^A-Za-z0-9-]" , "" , API_DECODED .decode ("utf-8" ))
32
53
33
- return API_DECODED_CLEAN
54
+ UNLOCKED_CONTENT = str (API_DECODED_CLEAN ).translate (tableContentUn )
55
+
56
+ return UNLOCKED_CONTENT
34
57
35
58
36
59
print ("\n Add your API here.\n NEVER CHANGE THE API KEY DIRECTLY\n FOR SECURITY REASONS!\n " )
37
60
userChange = input ("Enter API key: " ).strip ()
38
61
62
+ # Caesar Cipher
63
+ alphaCharset = string .ascii_letters
64
+ numCharset = string .digits
65
+ # Combine both alphaCharset with numCharset in one variable
66
+ charsetMain = alphaCharset + numCharset
67
+
68
+ totalNum = 0
69
+ for i in range (len (charsetMain )):
70
+ totalNum += i
71
+
72
+ # print(totalNum)
73
+ shiftAlpha = 4
74
+ shiftAlpha %= totalNum
75
+
76
+ alphaShifted = None
77
+ alphaShifted = charsetMain [shiftAlpha :] + charsetMain [:shiftAlpha ]
78
+ tableContent = str .maketrans (charsetMain , alphaShifted )
79
+
80
+ CIPHER_APPLIED = userChange .translate (tableContent )
81
+
39
82
# Pick userChange and encode it to base64
40
- userChange = base64 .b64encode (userChange .encode ('utf-8' ))
83
+ userChange = base64 .b64encode (CIPHER_APPLIED .encode ('utf-8' ))
41
84
# Save userChange to "API" file
42
85
with open (relative_to_assets ('Data/security/API' ), 'wb' ) as f :
43
86
# Delete everything inside the file.
0 commit comments