diff --git a/src/kasa_crypt/_crypt_impl.pyx b/src/kasa_crypt/_crypt_impl.pyx index 3d97b7b..0a77447 100644 --- a/src/kasa_crypt/_crypt_impl.pyx +++ b/src/kasa_crypt/_crypt_impl.pyx @@ -22,8 +22,8 @@ cdef char* _encrypt(const char *unencrypted): return encrypted def encrypt(string: str) -> bytes: - return _encrypt(string.encode('ascii')) + return _encrypt(string.encode('utf-8')) def decrypt(string: bytes) -> str: - return _decrypt(string).decode('ascii') + return _decrypt(string).decode('utf-8') diff --git a/src/kasa_crypt/crypt_wrapper.h b/src/kasa_crypt/crypt_wrapper.h index 56b4872..afdb0cc 100644 --- a/src/kasa_crypt/crypt_wrapper.h +++ b/src/kasa_crypt/crypt_wrapper.h @@ -8,7 +8,7 @@ void _encrypt_into(const char * unencrypted, char * encrypted) { uint8_t unencrypted_byte; uint8_t key = 171; - for(unsigned i = 0; i < strlen(unencrypted); i++) { + for(unsigned i = 0; i <= strlen(unencrypted); i++) { unencrypted_byte = unencrypted[i]; key = key ^ unencrypted_byte; encrypted[i] = key; @@ -18,7 +18,7 @@ void _decrypt_into(const char * encrypted, char * unencrypted) { uint8_t unencrypted_byte; uint8_t encrypted_byte; uint8_t key = 171; - for(unsigned i = 0; i < strlen(encrypted); i++) { + for(unsigned i = 0; i <= strlen(encrypted); i++) { encrypted_byte = encrypted[i]; unencrypted_byte = key ^ encrypted_byte; key = encrypted_byte;