obfuscator¶
This module contains a simple mechanism for obfuscating a set of data. Consider this “security through obscurity”. This module contains no encryption mechanisms!
Example:
>>> from obfuscator import obfuscate_xor, deobfuscate_xor
>>> data = [1, 2, 3, 4]
>>> key, odata = obfuscate_xor(data)
>>> key, odata
(162, [163, 160, 161, 166, 166, 154, 181, 60, 131, 24, 88, 35, 137, 240, 216, 161, 247, 218, 19, 116, 54, 21, 217, 190, 137, 81, 68, 200, 35, 210, 133, 139])
>>> assert data == deobfuscate_xor(key, odata)[:len(data)]
>>>
>>> key, odata = obfuscate_xor(data, minimum_length=0)
>>> assert data == deobfuscate_xor(key, odata)
>>>
- obfuscator.deobfuscate(key, data, encoder=1)¶
This function obfuscates the data using the default operation.
- obfuscator.deobfuscate_offset(key, data)¶
This function deobfuscates the data using an offset operation.
The formula used is: [x - key for x in data]
Parameters: - key (int) – The key used for the offset operation.
- data (iterable) – The data you want to obfuscate
- obfuscator.deobfuscate_rot13(key, data)¶
This function performs a ROT13 decode of the data. data needs to be an iterable that contains a representation of str types. This can be either a string of type str, or a list of bytes from something like ord.
Parameters: - key (int) – This value is ignored; it only exists to conform to the other methods.
- data (iterable) – The data you want to deobfuscate
- obfuscator.deobfuscate_xor(key, data)¶
This function deobfuscates the data using an byte-wise XOR operation.
The formula used is: [x ^ key for x in data]
Parameters: - key (int) – The key used for the XOR operation.
- data (iterable) – The data you want to obfuscate
- obfuscator.obfuscate(data, key=None, minimum_length=32, encoder=1)¶
This function obfuscates the data using the default operation.
- obfuscator.obfuscate_offset(data, key=None, minimum_length=32)¶
This function obfuscates the data using an offset operation.
The formula used is: [x + key for x in data]
Parameters: - data (iterable) – The data you want to obfuscate
- key (int) – The value used for the offset operation. By default, the value will be a random integer between 40 and 127.
- minimum_length (int) – The minimum number of bytes to return. If the encoding operation produces fewer bytes that this, random bytes are appended to the end of the result so len(bytes) == minimum_length.
- obfuscator.obfuscate_rot13(data, key=None, minimum_length=32)¶
This function performs a ROT13 encode on the data. data needs to be an iterable that contains a representation of str types. This can be either a string of type str, or a list of bytes from something like ord.
Parameters: - data (iterable) – The data you want to obfuscate
- key (int) – This value is ignored; it only exists to conform to the other methods.
- minimum_length (int) – The minimum number of bytes to return. If the encoding operation produces fewer bytes that this, random bytes are appended to the end of the result so len(bytes) == minimum_length.
- obfuscator.obfuscate_xor(data, key=None, minimum_length=32)¶
This function obfuscates the data using an byte-wise XOR operation.
The formula used is: [x ^ key for x in data]
Parameters: - data (iterable) – The data you want to obfuscate
- key (int) – The key used for the XOR operation. By default, the key will be a random integer between 1 and 255.
- minimum_length (int) – The minimum number of bytes to return. If the encoding operation produces fewer bytes that this, random bytes are appended to the end of the result so len(bytes) == minimum_length.
- obfuscator.rot13(data, minimum_length=32)¶
This function performs a ROT13 encode/decode on the data. data needs to be an iterable that contains a representation of str types. This can be either a string of type str, or a list of bytes from something like ord.
Parameters: - data (iterable) – The data you want to obfuscate
- minimum_length (int) – The minimum number of bytes to return. If the encoding operation produces fewer bytes that this, random bytes are appended to the end of the result so len(bytes) == minimum_length.