-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCre.py
57 lines (49 loc) · 1.7 KB
/
Cre.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import string
import random
def DC(info, s = 13, n = 5):
"""[File Encryptor/Decryptor]
Args:
info ([string]): [The data to be encrypted or decrypted]
s (int, optional): [The decipher key to string characters in data]. Defaults to 13.
n (int, optional): [The decipher key to int characters in data]. Defaults to 5.
Returns:
[string]: [The data after encryption or decryption]
"""
rtn = ""
for l in info:
if l.isalpha():
num=ord(l)+s
if (ord(l) in range(65, 91) and num<65) or (ord(l) in range(97, 123) and num <97):
num = 26 + num
elif (ord(l) in range(65, 91) and num>90) or (ord(l) in range(97, 123) and num>122):
num = num - 26
rtn += str(chr(num))
elif l.isnumeric():
rtn += str((int(l)+n)%10)
else:
rtn += str(l)
return rtn
def EnCre(filename):
"""[Reads the encryted credentials from the file
and returns a string of those credentials after
decrypting them in the fixed order]
Args:
filename ([string]): [the path/name of the file containing encrypted credentials]
Returns:
[string]: [Decrypted & ordered credentials]
"""
try:
with open(filename, "r") as file:
return DC(file.read()).split('\n')
except Exception as e:
print(e)
def PasswordGenerator():
"""[It generates random passwords for the new users]
Returns:
[string]: [the alphanumeric random password of the length of 8 characters]
"""
Password = ""
Rand = string.ascii_letters+string.digits
for i in range(8):
Password += random.choice(Rand)
return Password