fork download
  1. from cryptography.hazmat.primitives.ciphers import Chiper, algorithms, modes
  2. from cryptography.hazmat.backends import default_backend
  3. from binascii import hexlify as hexa
  4. from os import urandom
  5. k=urandom(16)
  6. iv=urandom(16)
  7. print("k=",hexa(k))
  8. cipher = Cipher(algorithms.AES(k), modes.CBC(iv), backend = default_backend())
  9. aes_encrypt = cipher.encryptor()
  10. p1=urandom(16)
  11. p2=urandom(16)
  12. p=p1+p2+p1
  13. c=aes_encrypt.update(p)+aes_encrypt.finalize()
  14. print("p=",hexa(p))
  15. print("c=",hexa(c))
  16. aes_decrypt = cipher.decryptor()
  17. p3=aes_decrypt.update(c)+aes_decrypt.finalize()
  18. print("p3",hexa(p3))
Runtime error #stdin #stdout #stderr 0.01s 118784KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 1, in <module>
    from cryptography.hazmat.primitives.ciphers import Chiper, algorithms, modes
ImportError: No module named cryptography