Saturday, October 22, 2016

Xor text with single byte

1- the script below

import binascii
import sys

text = "here are two important points to remember about dictionary keys "
xorkey = "r"
xorkey = sys.argv[1]
text = sys.argv[2]
print "** hexstring"
print binascii.hexlify(text)

def xorSingleByte(text, char):
    hextext = binascii.hexlify(text)
    xorres = ""
    for i in range(0,len(hextext),2):
        dpart = hextext[i:i+2]
        dint = int(dpart, 16)
        xorout = int(bin(dint ^ ord(char)),2)
        strhex = str(hex(xorout))[2:]
        if len(strhex) == 1:
            strhex = "0" + strhex
        xorres += strhex
    return xorres
  
afterxor = xorSingleByte(text, xorkey)
print "** hexstring after xor"
print afterxor




2- usage python xorsinglebyte.py xorkey text, example below xor the text with character r

$ python  xorsinglebyte.py r "Join the Stack Overflow Community"
** hexstring
4a6f696e2074686520537461636b204f766572666c6f7720436f6d6d756e697479
** hexstring after xor
381d1b1c52061a17522106131119523d041700141e1d0552311d1f1f071c1b060b

No comments:

Post a Comment