Skip to content

Instantly share code, notes, and snippets.

@moonbingbing
Created August 23, 2012 05:31
Show Gist options
  • Save moonbingbing/3432989 to your computer and use it in GitHub Desktop.
Save moonbingbing/3432989 to your computer and use it in GitHub Desktop.
python string xor sample
#!/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')
@uragan1987
Copy link

thx for sharing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment