Skip to content

Commit

Permalink
Speedup xor by using pseudo-SIMD
Browse files Browse the repository at this point in the history
  • Loading branch information
yunzheng committed Jan 8, 2024
1 parent 24444e0 commit aa15ef7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dissect/cobaltstrike/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@


def xor(data: bytes, key: bytes) -> bytes:
"""XOR data with key"""
"""XOR data with key (simd version)"""
if sum(key) == 0:
return data
data = bytearray(data)
for i in range(len(data)):
data[i] ^= key[i % len(key)]
return bytes(data)

size = len(data)
if len(key) < size:
key = key * ((size // len(key)) + 1)
key = key[:size]

return int.to_bytes(int.from_bytes(data, "little") ^ int.from_bytes(key, "little"), size, "little")


def netbios_encode(data: bytes, offset: int = 0x41) -> bytes:
Expand Down

0 comments on commit aa15ef7

Please sign in to comment.