Created
April 12, 2020 23:58
-
-
Save macostag/4e2e8712f6edfff32b256010b77550c7 to your computer and use it in GitHub Desktop.
XOR python script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import struct | |
import sys | |
#Single Byte XOR | |
def xor(data,key): | |
translated = ""; | |
for ch in data: | |
translated += chr(ord(ch) ^ key) | |
return translated | |
#NULL Ignoring XOR Encoding | |
def xorIgnNullKey(data,key): | |
translated = ""; | |
for ch in data: | |
if ch == "\x00" or ch == chr(key): | |
translated += ch | |
else : | |
translated += chr(ord(ch) ^ key) | |
return translated | |
#Multi-byte XOR Encoding | |
def four_byte_xor(content,key): | |
translated = "" | |
len_content = len(content) | |
index = 0 | |
while (index < len_content): | |
data = content[index:index+4] | |
p = struct.unpack("I",data)[0] | |
translated += struct.pack("I",p^key) | |
index +=4 | |
pass | |
return translated | |
out = xor ("#!4",0x40) | |
print out | |
out2 = xorIgnNullKey("hello\x00\x00\x00",0x4b) | |
print out2 | |
in_file = open("resource.bin",'rb') | |
out_file = open("enc_resource.bin",'wb') | |
xor_key = 0xEAD4AA34 | |
file_content = in_file.read() | |
enc_content = four_byte_xor(file_content,xor_key) | |
out_file.write(enc_content) | |
out_file.close() | |
enc_file = open("enc_resource.bin",'rb') | |
enc_file_content = enc_file.read() | |
dec_file = open("dec_resource.bin",'wb') | |
dec_file_content = four_byte_xor(enc_file_content,xor_key) | |
dec_file.write(dec_file_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment