Created
August 23, 2012 05:31
-
-
Save moonbingbing/3432989 to your computer and use it in GitHub Desktop.
python string xor sample
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 | |
# -*- coding: utf-8 -*- | |
import itertools | |
def xor(s, key): | |
key = key * (len(s) / len(key) + 1) | |
return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in itertools.izip(s, key)) | |
if __name__ == "__main__": | |
ret = xor('test','key') | |
print ret | |
print xor(ret, 'key') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx for sharing 👍