Answers for "Python xms"

1

python AES

from Crypto.Cipher import AES 
import binascii,os
import random, string

iv = os.urandom(16)
aes_mode = AES.MODE_CBC
key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16))
print(key)
encryptor = AES.new(key, aes_mode, iv)
def aes_encrypt(plaintext):
    plaintext = convert_to_16(plaintext)

    ciphertext = encryptor.encrypt(plaintext)
    return ciphertext

def convert_to_16(plaintext): #Overcome the drawback of plaintxt size which should be multiple of len(iv)
    add = 16 - (len(plaintext) % 16)
    return(plaintext + ' ' * add)


Encrypted = aes_encrypt('Jaisal ')
print("Encrypted message :",Encrypted)
Posted by: Guest on November-24-2020
8

python pil

from PIL import Image

img = Image.open("./my_image.png")
Posted by: Guest on July-14-2020

Browse Popular Code Answers by Language