From 58dce62706aa72a34e76cd4ca668b633ff9e395c Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Mon, 24 Jun 2024 16:55:30 +0200 Subject: [PATCH] Add project files --- LICENSE | 2 +- obf/__init__.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 obf/__init__.py diff --git a/LICENSE b/LICENSE index c06137c..920dc4f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Julian Müller +Copyright (c) 2024 Julian Müller (ChaoticByte) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/obf/__init__.py b/obf/__init__.py new file mode 100644 index 0000000..03add9a --- /dev/null +++ b/obf/__init__.py @@ -0,0 +1,45 @@ +# Copyright (c) 2024 Julian Müller (ChaoticByte) +# License: MIT + +def obf(data: bytes, key: bytes, decrypt: bool = False, iterations: int = 64) -> bytes: + assert type(data) == bytes + assert type(key) == bytes + assert type(iterations) == int + assert type(decrypt) == bool + data = bytearray(data) + key = bytearray(key) + len_data = len(data) + len_key = len(key) + def a(d): + # shift (encrypt) + if not decrypt: + for i in range(len_data): + n = key[i % len_key] + d[i] = (d[i] + n) % 256 + # transpose + swap_indices = [] # list of tuples that stores transposition data (from, to) + k = 0 + for i in range(len_data): + k += i + key[i % len_key] # we add to k + j = k % len_data # and use it to make cryptanalysis harder (I think?) + swap_indices.append((i, j)) # store transposition data + if decrypt: + swap_indices.reverse() + for a, b in swap_indices: + # swap values + a_ = d[a] + b_ = d[b] + d[a] = b_ + d[b] = a_ + # unshift (decrypt) + if decrypt: + for i in range(len_data): + n = key[i % len_key] + b = d[i] - n + while b < 0: + b = 256 + b + d[i] = b + return d + for i in range(iterations): + data = a(data) + return bytes(data)