This module contains a file-level interface for the XOR obfuscation methods.
Parameters: | filename (str) – The path of the file you want to read/write. |
---|
This class represents an obfuscated data file. You can use this to store some-what sensitive information inside a file. The documentation for some of the functions is purposely light.
Example #1 - Storing a string:
>>> from obfuscator.file import ObfuscatedFile
>>> of = ObfuscatedFile('data.bin')
>>> bytes = map(ord, "my string")
>>> of.write(bytes) # data.bin is 32 bytes long
86 # The random key used for encoding; stored in the file
>>> read_bytes = of.read()
>>> read_bytes
[109L, 121L, 32L, 115L, 116L, 114L, 105L, 110L, 103L]
>>> ''.join(map(chr, read_bytes))
'my string'
Example #2 - Storing a string with known key:
>>> from obfuscator.file import ObfuscatedFile
>>> of = ObfuscatedFile('data.bin')
>>> bytes = map(ord, "my string")
>>> my_key = 0xCF
>>> of.write(bytes, my_key) # data.bin is 32 bytes long
207
>>> read_bytes = of.read() # Notice how we didn't use a key
>>> ''.join(map(chr, read_bytes))
',8a253(/&'
>>> # The string is wrong because the key is not stored in the file
>>> read_bytes = of.read(key=my_key)
>>> ''.join(map(chr, read_bytes))
'my string'
>>>
This function reads a file written by write, and returns the deobfuscated data.
Parameters: | key (int) – The key used during write(). NOTE: If you passed in a key during write(), you must use the same key here; the key will not be stored in the file. If you let the algorithm choose the key, it is stored in the file, and will be used during read(). |
---|
Write the data to a file.
Parameters: |
|
---|