!pip install pycryptodome
Defaulting to user installation because normal site-packages is not writeable Collecting pycryptodome Obtaining dependency information for pycryptodome from https://files.pythonhosted.org/packages/00/e6/73931df4046e34a6354d323b4a5b5c18e5184f4a08687806ee3353c81a6b/pycryptodome-3.19.0-cp35-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata Downloading pycryptodome-3.19.0-cp35-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.4 kB) Downloading pycryptodome-3.19.0-cp35-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 1.7 MB/s eta 0:00:00m eta 0:00:01[36m0:00:01 Installing collected packages: pycryptodome Successfully installed pycryptodome-3.19.0
from Crypto.Cipher import ARC4
cipher = ARC4.new(b'Key')
ct = cipher.encrypt(b'Plaintext')
ct
b'\xbb\xf3\x16\xe8\xd9@\xaf\n\xd3'
' '.join(f'{c:02X}' for c in ct)
'BB F3 16 E8 D9 40 AF 0A D3'
' '.join(f'{c:08b}' for c in ct)
'00010001 01001000 00001101 01001101 00011010 00101010 01101100 11111001'
cipher = ARC4.new(b'Key')
cipher.decrypt(ct)
b'Plaintext'
cipher.decrypt(ct) #!stream cipher
b'\xa2\xb9>\x8fo\x02:\x07\x8e'
b'\x01\x61\x41'
b'\x01aA'
bytes.fromhex('016141')
b'\x01aA'
from Crypto.Cipher import DES
cipher = DES.new(b'12345678', DES.MODE_ECB)
ct = cipher.encrypt(b'HelloAll')
ct
b'\x11H\rM\x1a*l\xf9'
cipher.decrypt(ct)
b'HelloAll'
from Crypto.Cipher import ChaCha20
from Crypto.Random import get_random_bytes
plaintext = b'Attack at dawn'
key = get_random_bytes(32)
cipher = ChaCha20.new(key=key)
ct = cipher.encrypt(plaintext)
ct
b'-Ip\xf9\xd2\x9cdgj\xd8\x9ai\x061'
cipher.nonce
b'g\x0e\xb44\xd1\xa4\xcf\xaf'
' '.join(f'{c:02X}' for c in cipher.nonce)
'67 0E B4 34 D1 A4 CF AF'
cipher = ChaCha20.new(key=key, nonce=cipher.nonce)
plaintext = cipher.decrypt(ct)
plaintext
b'Attack at dawn'