Skip to content

Commit

Permalink
feat: add code
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jun 16, 2023
1 parent a9fe699 commit dad4184
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/kasa_crypt/kasa_crypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from struct import pack


def encrypt(string: str) -> bytes:
"""Encrypt."""
unencrypted = bytearray(string.encode())
key = 171
unencrypted_len = len(unencrypted)
encrypted = bytearray(unencrypted_len)
for idx, unencryptedbyte in enumerate(unencrypted):
key = key ^ unencryptedbyte
encrypted[idx] = key
return pack(">I", unencrypted_len) + encrypted


def decrypt(string: bytes) -> str:
"""Decrypt."""
key = 171
result = bytearray(string)
for idx, i in enumerate(string):
a = key ^ i
key = i
result[idx] = a
return result.decode()
2 changes: 0 additions & 2 deletions src/kasa_crypt/main.py

This file was deleted.

0 comments on commit dad4184

Please sign in to comment.