Skip to content

Instantly share code, notes, and snippets.

@syxc
Created July 9, 2015 09:52
Show Gist options
  • Save syxc/f0ad34edb1fc7e7ebc08 to your computer and use it in GitHub Desktop.
Save syxc/f0ad34edb1fc7e7ebc08 to your computer and use it in GitHub Desktop.
simpleXor
#!/usr/bin/env python
# encoding: utf-8
"""
xor.py
"""
import base64
def simpleXor(source, key):
retval = ''
j = 0
for ch in source:
retval = retval + chr(ord(ch)^ord(key[j]))
j = j + 1
j = j % (len(key))
return retval
def main():
base_data = 'muid=0f074dc8e1f0547310e729032ac0730b&conv_time=1422263664&client_ip=10.11.12.13&sign=8a4d7f5323fd91b37430d639e6f7371b'
encrypt_key = 'test_encrypt_key'
encrypted = base64.b64encode(simpleXor(base_data, encrypt_key))
print("Encrypted: " + encrypted)
decrypted = simpleXor(base64.b64decode(encrypted), encrypt_key)
print("Decrypted: " + decrypted)
pass
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment