Setup is quick and easy — just run pip install pycrypto!
Encryption
from Crypto.Cipher import AES, DES
import random
public = b'randomsecretkey1'
private = b'randomsecretkey2'
cipher = AES.new(public, AES.MODE_CFB, private)
msg = private + cipher.encrypt('password1234!')
print(msg)
In any encrypted password, there is a public and private key. The public key is used for the original decryption, and the private key is used IN the password. This encryption method, AES (Advanced Encryption Standard), is much cryptographically secure than DES (Data Encryption Standard). It is recommended to have a random/special character private, so below is a small script to do that. The public and private keys are both 16 characters.
exec("private = b'" + "".join(["\\x" + random.choice(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']) + random.choice(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']) for x in range(16)]) + "'")
Decryption
from Crypto.Cipher import AES, DES
import random
public = b'randomsecretkey1'
private = b'randomsecretkey2'
cipher = AES.new(public, AES.MODE_CFB, private)
print(cipher.decrypt(encrypted_password)[16:].decode("utf-8"))
You must securely save both the public and private key. The decryption script is simple. Provide the both the keys, then use the object to decrypt the password. The password will be a jumble of random special characters, but that's what makes it so secure. Some might argue CAST, ARC, DES, RSA, or manual ciphering is better, but this is the best, because of it's complexity, use of two keys, and use of special characters.
What I Learned
I learned how to use the Crypto module for python. I have never been in this area, so this was brand new for me. Looking at the documentation and experimenting with scary encryption stuff was fun :).
Built With
- pycrypto
- python

Log in or sign up for Devpost to join the conversation.