Simplecrypt Python Error
I am using the simplecrypt library to encrypt a file, however I cannot seem to read the file in a way that simplecrypt can decode it. Encryption code: from simplecrypt import encr
Solution 1:
Aha... Minor mistake :-)
According to the docs in the link you provided in your question, the arguments to symplecrypt.encrypt
and simplecrypt.decrypt
are ('password', text)
. In your code you've got that inverted ( (text, key)
). You're passing the text to encrypt/decrypt in the first argument and the key in the second. Just reverse that order and will work.
Working example:
from simplecrypt import encrypt, decrypt
defencrypt_file(file_name, key):
withopen(file_name, 'rb') as fo:
plaintext = fo.read()
print"Text to encrypt: %s" % plaintext
enc = encrypt(key, plaintext)
withopen(file_name + ".enc", 'wb') as fo:
fo.write(enc)
defdecrypt_file(file_name, key):
withopen(file_name, 'rb') as fo:
ciphertext = fo.read()
dec = decrypt(key, ciphertext)
print"decrypted text: %s" % dec
withopen(file_name[:-4], 'wb') as fo:
fo.write(dec)
if __name__ == "__main__":
encrypt_file("test.txt", "securepass")
decrypt_file("test.txt.enc", "securepass")
Post a Comment for "Simplecrypt Python Error"