-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwordCalc.py
61 lines (52 loc) · 1.85 KB
/
passwordCalc.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
61
#!/usr/bin/python3
import hashlib
import time
serialNumber = b'122112123456'
userName = b'installer'
DEFAULT_REALM = b'enphaseenergy.com'
gSerialNumber = None
def emupwGetPasswdForSn(serialNumber, userName, realm):
if serialNumber == None or userName == None:
return None
if realm == None:
realm = DEFAULT_REALM
return hashlib.md5(b'[e]' + userName + b'@' + realm + b'#' + serialNumber + b' EnPhAsE eNeRgY ').hexdigest()
def emupwGetPasswd(userName,realm):
global gSerialNumber
if gSerialNumber:
return emupwGetPasswdForSn(gSerialNumber, userName, realm);
return None;
def emupwGetPublicPasswd(serialNumber, userName, realm, expiryTimestamp=0):
if expiryTimestamp==0:
expiryTimestamp = int(time.time());
return hashlib.md5(userName + b'@' + realm + b'#' + serialNumber + b'%d' % expiryTimestamp).hexdigest()
def emupwGetMobilePasswd(serialNumber,userName,realm=None):
global gSerialNumber
gSerialNumber = serialNumber
digest = emupwGetPasswdForSn(serialNumber,userName,realm)
countZero = digest.count('0')
countOne = digest.count('1')
password = ''
for cc in digest[::-1][:8]:
if countZero == 3 or countZero == 6 or countZero == 9:
countZero = countZero -1
if countZero > 20:
countZero = 20
if countZero < 0:
countZero = 0
if countOne == 9 or countOne == 15:
countOne = countOne -1
if countOne > 26:
countOne = 26
if countOne < 0:
countOne = 0
if cc == '0':
password += chr(ord('f') + countZero)
countZero = countZero - 1
elif cc == '1':
password += chr(ord('@') + countOne)
countOne = countOne -1
else:
password += cc
return password
print(emupwGetMobilePasswd(serialNumber,userName))