Closed aceresia closed 6 years ago
You will need to reverse engineer the code for python conversion, The code uses the standard crypto library and some modification to do the hash.
I'm trying to create a python version of this for home assistant. Do you know what type of cryptology is being used in the function "cryptokeyFromAddress"? Is it a standard one or proprietary crypto from Mitsubishi?
Hi, Did you figure it out yet? Thanks
Yes Here it is `
def __l2char(l):
r = ''
for c in l:
r += chr(c)
return r
def __l2h(l):
result = ''
for i in l:
if i < 16:
result += '0'
result += i.toString(16)
return result
def __h2l(h):
r = []
for i in range(0, len(h)-1)[::2]:
r.append(int(h[i:i+2], 16))
return r
def __unicodeList(l):
result = []
for i in l:
result.append(ord(i))
return result
def __cryptokeyFromAddress(dt):
W = __h2l(__W)
p = base64.b64decode(__password)
hash_string = p.decode('latin1', 'replace') + dt
dt1 = hashlib.sha256(hash_string.encode("latin1")).hexdigest()
dt1_l = __h2l(dt1)
dt2 = ''
for i in range(0, 88):
dt2 += '00'
dt3 = __h2l(dt2)
dt3[64] = 8
dt3[65] = 64
dt3[32:64] = dt1_l
dt3[66] = self.__S
cryptoserial = __h2l(__cryptoSerial)
dt3[79] = cryptoserial[8]
dt3[80] = cryptoserial[4]
dt3[81] = cryptoserial[5]
dt3[82] = cryptoserial[6]
dt3[83] = cryptoserial[7]
dt3[84] = cryptoserial[0]
dt3[85] = cryptoserial[1]
dt3[86] = cryptoserial[2]
dt3[87] = cryptoserial[3]
dt3[0:32] = W
hash_string = __l2char(dt3)
result = hashlib.sha256(hash_string.encode("latin1")).hexdigest()
return result
`
Just ported from node to python.
Yes Here it is `
def __l2char(l): r = '' for c in l: r += chr(c) return r def __l2h(l): result = '' for i in l: if i < 16: result += '0' result += i.toString(16) return result def __h2l(h): r = [] for i in range(0, len(h)-1)[::2]: r.append(int(h[i:i+2], 16)) return r def __unicodeList(l): result = [] for i in l: result.append(ord(i)) return result def __cryptokeyFromAddress(dt): W = __h2l(__W) p = base64.b64decode(__password) hash_string = p.decode('latin1', 'replace') + dt dt1 = hashlib.sha256(hash_string.encode("latin1")).hexdigest() dt1_l = __h2l(dt1) dt2 = '' for i in range(0, 88): dt2 += '00' dt3 = __h2l(dt2) dt3[64] = 8 dt3[65] = 64 dt3[32:64] = dt1_l dt3[66] = self.__S cryptoserial = __h2l(__cryptoSerial) dt3[79] = cryptoserial[8] dt3[80] = cryptoserial[4] dt3[81] = cryptoserial[5] dt3[82] = cryptoserial[6] dt3[83] = cryptoserial[7] dt3[84] = cryptoserial[0] dt3[85] = cryptoserial[1] dt3[86] = cryptoserial[2] dt3[87] = cryptoserial[3] dt3[0:32] = W hash_string = __l2char(dt3) result = hashlib.sha256(hash_string.encode("latin1")).hexdigest() return result
`
Just ported from node to python.
Great! Thanks a lot! Is there anyway you could share your complete project in python? like src, files, libs, etc. It would be greatly appreciated. I don't have whole bunch of experience so python is easier for me to work with. Thanks again for your time.
I'm trying to create a python version of this for home assistant. Do you know what type of cryptology is being used in the function "cryptokeyFromAddress"? Is it a standard one or proprietary crypto from Mitsubishi?