Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update encryption for new firmware/devices #49

Closed
Enzo-Matrix opened this issue Nov 18, 2018 · 2 comments
Closed

Update encryption for new firmware/devices #49

Enzo-Matrix opened this issue Nov 18, 2018 · 2 comments

Comments

@Enzo-Matrix
Copy link

The pyHS100 has a working encrypt/decrypt function in protocol.py which should be used to fixed new firmware/devices issue. See below for the code I literally copied from that project:

# Encryption and Decryption of TP-Link Smart Home Protocol
# XOR Autokey Cipher with starting key = 171
def encrypt(request: str) -> bytearray:
        key = 171
        plainbytes = request.encode()
        buffer = bytearray(struct.pack(">I", len(plainbytes)))

        for plainbyte in plainbytes:
                cipherbyte = key ^ plainbyte
                key = cipherbyte
                buffer.append(cipherbyte)

        return bytes(buffer)

def decrypt(ciphertext: bytes) -> str:
        key = 171 
        buffer = []

        for cipherbyte in ciphertext:
                plainbyte = key ^ cipherbyte
                key = cipherbyte
                buffer.append(plainbyte)

                plaintext = bytes(buffer)

        return plaintext.decode()
@sylvandb
Copy link

sylvandb commented Dec 5, 2018

other than being python3, that looks functionally equivalent to me. in what respect is the softScheck version incorrect?

@Enzo-Matrix
Copy link
Author

Enzo-Matrix commented Dec 11, 2018

I don't understand python well enough to say why. But I was not getting any returned result when ran against HS210 dinner.

Looks like I was running a very old version of tplink-smartplug. The blog shows the code was update back in July 2018.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants