softScheck / tplink-smartplug

TP-Link WiFi SmartPlug Client and Wireshark Dissector
Apache License 2.0
1.14k stars 296 forks source link

Python3 support #20

Closed droberin closed 4 years ago

droberin commented 7 years ago

Hi! I'm trying to port this into Python3. Any help?

nadigo commented 7 years ago

trying to, there is an issue with strings diff between 2.X and 3

'str' does not support the buffer interface

mjfwest commented 7 years ago

changing the line sock_tcp.send(encrypt(cmd)) to sock_tcp.send(encrypt(cmd).encode()) will fix the string bytes issue . (I think, I am still testing)

mjfwest commented 7 years ago

Ok it was more than I thought. changing the following functions works in py3, (but will break py2)

def encrypt(string):
    key = 171
    result = b"\0\0\0"+ chr(len(string)).encode('latin-1')
    for i in string.encode('latin-1'):
        a = key ^ i
        key = a
        result += chr(a).encode('latin-1')
    return result

def decrypt(string):
    key = 171 
    result = ""
    for i in string: 
        a = key ^ i
        key = i 
        result += chr(a)
    return result
droberin commented 7 years ago

Thanks, mate. I guess you can send a pull-request with this. Perhaps a python3 version instead of merging inside python2 version. Python2.7 is 7 years old... perhaps it's time to let it go a little.

mjfwest commented 7 years ago

I'll try and do a pull request with py 2/3 compatibility, whenever I get round to it.

mjfwest commented 7 years ago

Fixed in pull request #25

softScheck commented 4 years ago

Python 3 support is added now.