XOR files and safely save them in server storage.
Interacting with Malicious file may cause many problems in your server/system.
The FXOR can help you write
and read
files byte by byte changing data
with XOR operator and provided as a IO Base class.
To use fxor you need to understand basic of it. first of all you need some arguments :
- An integer key in range(0, 256)
- Path to a file
- File open mode
w
for write mode orr
for read mode- Fast mode for
True
orFalse
which effects writing speed and memory usage- File real name or even None
Now let's see what does each one of these arguments do:
- key is used for XOR operation and you need same key for reading a file XORed with that key.
- Path to a file or XORed file in read mode
- Open mode
- Fast mode which can use more RAM if you set it to
True
- File name if you need to use.
from fxor import FileXOR
chunk_size = 1024 * 1024 # 1 MB
# Write/Create new file
with FileXOR(8, "path/to/output_file", "w", True, "output_file") as f:
with open("path/to/input_file", "rb") as f2:
while True:
data = f2.read(chunk_size)
f.update_write(data)
if len(data) < chunk_size:
break
# Read from XORed file
with FileXOR(8, "path/to/input_file", "r", True, "input_file") as f:
with open("path/to/output_file", "wb") as f2:
while True:
data = f.read(chunk_size)
f2.write(data)
if len(data) < chunk_size:
break
python3 fxor.py "1.jpg" "2.enc" 8 "w"
python3 fxor.py "2.enc" "2.jpg" 8 "r"
Here is the arguments we passed :
- File name to open
- File name to write to
- The key
- File open mode