AES
From charlesreid1
from Crypto.Cipher import AES
from Crypto.Util import RFC1751
from Crypto import Random
AES_MODE = AES.MODE_CBC
def encrypt(text, key):
text += '\0' * (16 - (len(text) % 16))
IV = Random.new().read(AES.block_size)
crypto = AES.new(key, AES_MODE, IV=IV)
return IV + crypto.encrypt(text)
def decrypt(ciphertext, key):
crypto = AES.new(key, AES_MODE, IV=ciphertext[:AES.block_size])
plain = crypto.decrypt(ciphertext[AES.block_size:])
return plain.rstrip('\0')
if __name__ == '__main__':
key = Random.new().read(32)
text = "This is a test"
ciphertext = encrypt(text, key)
print("Plaintext was '%s'" % decrypt(ciphertext, key))
print("Key was '%s'" % RFC1751.key_to_english(key))
https://www.reddit.com/r/cryptography/comments/4yu7mh/code_review_of_aes_implementation_in_python/
| Crypto cryptography-related resources on the wiki
Password Cracking: John the Ripper Constructing Wordlists: Kali/Wordlists and Metasploit/Wordlists Implementing AES Cipher in Python: AES
Category:Crypto · Category:Security · Category:Encryption
|
| Python a powerful programming language
Scientific Python: Data analysis libraries: Scipy · Numpy · Pandas · Statsmodel Machine learning libraries: Sklearn Neural network libraries: Tensorflow · Keras Plotting/viz: Matplotlib · Seaborn · Jupyter Solving partial differential equations and bessel functions: Fipy · Bessel Functions
Web and Networking Python: Web programming: Flask · Webapps · Mechanize · Scrapy · Gunicorn Wifi: Wireless/Python · Scapy IPython and Jupyter: Jupyter
Drawing, Geometry, and Shapes: Shapely (for drawing shapes): Shapely Geography library: Geos
General Useful Python Utilities: Python Remote Objects: Pyro Logging (create multi-channel log messages): Logging Keyboard (control keyboard from Python): Keyboard
Black Hat Python: Network scanning: Python/Scanner
|