-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashConversion.py
60 lines (41 loc) · 1.32 KB
/
HashConversion.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
58
59
60
import hashlib
def hash256(text,salt):
text = text.encode()
salt = salt.encode()
return hashlib.sha256(text+salt).hexdigest()
secret_key = "s3cr3t"
def password(plaintext,salt):
salt1 = hash256(secret_key,salt)
hsh = hash256(plaintext,salt1)
return "".join((salt1,hsh))
def generatepassword(plaintext,salt,alp,length=10):
alphabet = ('abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'0123456789')
if(alp == 1):
alphabet = alphabet + '!@#$%^&*()-_'
hexdig = password(plaintext,salt)
num = int(hexdig,16)
num_chars = len(alphabet)
chars = []
while len(chars) < length:
num, idx = divmod(num, num_chars)
chars.append(alphabet[idx])
return ''.join(chars)
a=input("Enter username : ")
b=input("Enter website name : ")
c=int(input("Enter 1 if you want special character or else enter 0 : "))
d=generatepassword(a,b,c)
import json
def writeToJSONFile(path, fileName, data):
filePathNameWExt = './' + path + '/' + fileName + '.json'
with open(filePathNameWExt, 'a') as fp:
#json.dump("data=",fp)
json.dump(data, fp)
# Example
path = './'
fileName='data'
data = {}
data['username1'] = a
data['password1']=d
writeToJSONFile(path,fileName,data)