0
Encrypt file using DES?
2 Answers
+ 1
thank youđč
0
You'll need to install a package such as pycrypto.
Then you will be able to use it such as;
from Crypto.Cipher import DES
key = "UserKeyOrPassword"
message = 'message or info to encrypt'
mode = DES.MODE_ECB
def pad(txt):
while len(txt) % 8 != 0:
txt += ' '
return txt
des = DES.new(key, mode)
message = pad(message)
encrypted_msg = des.encrypt(message)
print(encrypted_msg)
print(des.decrypt(encrypted_msg))
I would however suggest that you use AES instead.
https://pypi.org/project/pycrypto/
https://www.dlitz.net/software/pycrypto/
Make sure you read the API documentation for usage.
https://www.dlitz.net/software/pycrypto/api/current/