Encrypt file using DES? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Encrypt file using DES?

Python

20th Apr 2020, 11:37 PM
Maitha
2 Answers
+ 1
thank you🌹
21st Apr 2020, 10:06 AM
Maitha
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/
21st Apr 2020, 6:34 AM
ChaoticDawg
ChaoticDawg - avatar