Skip to content

Instantly share code, notes, and snippets.

@Edu4rdSHL
Created February 26, 2021 00:37
Show Gist options
  • Save Edu4rdSHL/069cd46654f4843adf5583ae3b4d5d06 to your computer and use it in GitHub Desktop.
Save Edu4rdSHL/069cd46654f4843adf5583ae3b4d5d06 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import sys
KEY = 'x'
def xor(data, key):
key = str(key)
l = len(key)
output_str = ""
for i in range(len(data)):
current = data[i]
current_key = key[i % len(key)]
output_str += chr(ord(current) ^ ord(current_key))
return output_str
def printCiphertext(ciphertext):
print('{ 0x' + ', 0x'.join(hex(ord(x))[2:] for x in ciphertext) + ' };')
try:
plaintext = open(sys.argv[1], "rb").read()
except:
print("File argument needed! %s " % sys.argv[0])
sys.exit()
ciphertext = xor(plaintext, KEY)
print('{ 0x' + ', 0x'.join(hex(ord(x))[2:] for x in ciphertext) + ' };')
@beboynew
Copy link

that's the thing, i'm new in all of this and wathever key i try to write i always get an error "SyntaxError: invalid character '“' (U+201C)"
so i wondered what i could use as a key, because i keep getting this and an error that specify what's the problem
"File "/home/user/xor_file.py", line 2
KEY = “10110111” no matter what i try either binary (here) or letters i don't know what key i should use

@Edu4rdSHL
Copy link
Author

Do you know that it's a pythons script, right? You need to run it using python2.

@beboynew
Copy link

Do you know that it's a pythons script, right? You need to run it using python2.

i'm a real dumbass, thank's for taking your time man, really . I kept running it wrongly ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment