Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthuralvim/b4823b4bf0fbb2e1e9b1 to your computer and use it in GitHub Desktop.
Save arthuralvim/b4823b4bf0fbb2e1e9b1 to your computer and use it in GitHub Desktop.
Encryption example.
# -*- coding: utf-8 -*-
from Crypto.Cipher import XOR
import base64
import functools
import hashlib
def func_encrypt(key, plaintext):
cipher = XOR.new(key)
return base64.b64encode(cipher.encrypt(plaintext))
def func_decrypt(key, ciphertext):
cipher = XOR.new(key)
return cipher.decrypt(base64.b64decode(ciphertext))
secret_key_word = 'password'
secret_key = hashlib.sha256(secret_key_word).digest()
encrypt = functools.partial(func_encrypt, secret_key)
decrypt = functools.partial(func_decrypt, secret_key)
string_encrypted = encrypt('Mensagem Protegida.')
print string_encrypted
string_decrypted = decrypt(string_encrypted)
print string_decrypted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment