Created
January 10, 2009 05:15
-
-
Save opie4624/45393 to your computer and use it in GitHub Desktop.
Puzzles for Hackers
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
Solutions to the "Puzzles for Hackers" book by Ivan Skylarov | |
ISBN10: 1-931769-45-1 |
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
>>> from xorencdec import xorencdec | |
>>> xorencdec('creature_creature_creature',']VTYJQC]aGC]_PDJ[{RJ[EEMLA') | |
'>$18>$18>$18>$18>$18>$18>$' | |
>>> xorencdec('Smith','>$18') | |
'mIXLV' | |
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
def xorencdec(a, b, debug=False): | |
if debug: | |
print a," Length: ",len(a) | |
print b," Length: ",len(b) | |
if len(a) < len(b): | |
key,string = a,b | |
else: | |
key,string = b,a | |
if debug: | |
print "Key: ",key," [",len(key),"]" | |
print "String: ",string," [",len(string),"]" | |
wkey=i=0 | |
output='' | |
while i<len(string): | |
if wkey == len(key): | |
wkey = 0 | |
if debug: | |
print "",key | |
print " "*wkey,"^ ",wkey | |
print "",string | |
print " "*i,"^ ",i | |
print key[wkey],"^",string[i]," = ",chr(ord(string[i])^ord(key[wkey])) | |
output += chr(ord(string[i])^ord(key[wkey])) | |
wkey += 1 | |
i+=1 | |
return output | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment