Last active
August 29, 2015 14:15
-
-
Save arthuralvim/b4823b4bf0fbb2e1e9b1 to your computer and use it in GitHub Desktop.
Encryption example.
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
# -*- 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