[util] implement 'decrypt_xor()'

This commit is contained in:
Mike Fährmann
2025-03-04 16:32:27 +01:00
parent b5c1bf3f59
commit 5486a9c429
3 changed files with 19 additions and 27 deletions

View File

@@ -48,6 +48,19 @@ def bdecode(data, alphabet="0123456789"):
return num
def decrypt_xor(encrypted, key, base64=True, fromhex=False):
if base64:
encrypted = binascii.a2b_base64(encrypted)
if fromhex:
encrypted = bytes.fromhex(encrypted.decode())
div = len(key)
return bytes([
encrypted[i] ^ key[i % div]
for i in range(len(encrypted))
]).decode()
def advance(iterable, num):
""""Advance 'iterable' by 'num' steps"""
iterator = iter(iterable)