init
This commit is contained in:
commit
4797a57f1e
5 files changed
+51
No files matched your search
@@ -0,0 +1,2 @@
|
||||
ctext
|
||||
key
|
||||
@@ -0,0 +1,30 @@
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import pad
|
||||
from Crypto.Random import get_random_bytes
|
||||
|
||||
|
||||
# Generate new secret key
|
||||
with open('key', 'wb') as f:
|
||||
f.write(get_random_bytes(16))
|
||||
|
||||
plaintext = input("Please input the message: ")
|
||||
|
||||
# Pad plaintext
|
||||
plaintext = plaintext.encode()
|
||||
|
||||
plaintext = pad(plaintext, 16)
|
||||
|
||||
# Read Key
|
||||
with open('key', 'rb') as f:
|
||||
aes_key = f.read()
|
||||
|
||||
# Encrypt and send (write) message
|
||||
cipher = AES.new(aes_key, AES.MODE_CBC)
|
||||
|
||||
ciphertext = cipher.encrypt(plaintext)
|
||||
|
||||
with open('ctext', 'wb') as f:
|
||||
f.write(ciphertext)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import unpad
|
||||
|
||||
# Read Key
|
||||
with open('key', 'rb') as f:
|
||||
aes_key = f.read()
|
||||
|
||||
cipher = AES.new(aes_key, AES.MODE_CBC)
|
||||
|
||||
# Read message and decrypt
|
||||
|
||||
with open('ctext', 'rb') as f:
|
||||
ciphertext = f.read()
|
||||
|
||||
plaintext = unpad(cipher.decrypt(ciphertext), 16)
|
||||
|
||||
print(f'Plaintext: {plaintext}')
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pycryptodome==3.23.0
|
||||
Reference in new issue
Block a user