Skip to content

Instantly share code, notes, and snippets.

@Equinox-
Last active Oct 6, 2015
Embed
What would you like to do?
Added support for back conversion.
#!/usr/bin/python
def stringToInt(name):
name=name[::-1]
val=0
offset=0
for char in name:
val = val + ((ord(char) & 0xff) << offset)
offset = offset + 8
return val
def intToString(val):
name=""
offset=0
while 1==1:
ascii=(val >> offset) & 0xff
if ascii == 0:
break
name = name + chr(ascii)
offset = offset + 8
return name[::-1]
def findMask(f,t):
fVal=stringToInt(f)
tVal=stringToInt(t)
return (fVal ^ tVal)
ostring=raw_input("From? ")
mask=findMask(ostring,raw_input("To? "))
print mask
print intToString(stringToInt(ostring) ^ mask)
print "Convert Back!"
ostring=raw_input("Input? ")
mask=raw_input("Mask? ")
print intToString(stringToInt(ostring) ^ long(mask))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment