Last active
October 6, 2015 04:18
-
-
Save Equinox-/2934935 to your computer and use it in GitHub Desktop.
Added support for back conversion.
This file contains 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
#!/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