A Python module to encrypt and decrypt data with AES-128 CFB mode.

Overview

cryptocfb

PayPal Donate PyPI version Downloads Documentation Status

A Python module to encrypt and decrypt data with AES-128 CFB mode.

This module supports 8/64/128-bit CFB mode. It can encrypt and decrypt large data part by part. It also can do encryption and decryption inplace to reduce memory footprint.

Installation

pip install cryptocfb

Usage

>>> from cryptocfb import CryptoCFB
>>>
>>> key = b'0123456789abcdef'
>>> iv = bytes(reversed(key))
>>> cfb = CryptoCFB(key, iv)
>>>
>>> plain = b'This is a long message that needs to be encrypted.'
>>> cipher = cfb.encrypt(plain)
>>> cipher
bytearray(b"_#\xbf\x02\xd6\x19\x0c)\xd9\x18\xaf\xb9\xa4{JP\xf6j\xa3\xb2\xb2\xc6b\x9f\xae\x82\xa5\xd4\xaeen\xde\x12\x16\xfb\xf6\x079\x83\xd2\xbdC\'\x93\x9e\xc3\xeb\xc7\x03\x82")
>>> len(plain)
50
>>> len(cipher)
50
>>> cfb.reset_vector()
>>>
>>> cfb.decrypt(cipher)
bytearray(b'This is a long message that needs to be encrypted.')
>>> cfb.reset_vector()
>>>
>>> ba = bytearray(plain)
>>> ba1 = ba[0:16]
>>> ba2 = ba[16:32]
>>> ba3 = ba[32:48]
>>> ba4 = ba[48:64]
>>> cfb.crypt_inplace(ba1)
bytearray(b'_#\xbf\x02\xd6\x19\x0c)\xd9\x18\xaf\xb9\xa4{JP')
>>> cfb.crypt_inplace(ba2)
bytearray(b'\xf6j\xa3\xb2\xb2\xc6b\x9f\xae\x82\xa5\xd4\xaeen\xde')
>>> cfb.crypt_inplace(ba3)
bytearray(b"\x12\x16\xfb\xf6\x079\x83\xd2\xbdC\'\x93\x9e\xc3\xeb\xc7")
>>> cfb.crypt_inplace(ba4)
bytearray(b'\x03\x82')
>>> cfb.reset_vector()
>>>
>>> cfb.crypt_inplace(ba1, False)
bytearray(b'This is a long m')
>>> cfb.crypt_inplace(ba2, False)
bytearray(b'essage that need')
>>> cfb.crypt_inplace(ba3, False)
bytearray(b's to be encrypte')
>>> cfb.crypt_inplace(ba4, False)
bytearray(b'd.')
>>> cfb.reset_vector()
>>>
>>> ba
bytearray(b'This is a long message that needs to be encrypted.')
>>> cfb.crypt_inplace(ba)
bytearray(b"_#\xbf\x02\xd6\x19\x0c)\xd9\x18\xaf\xb9\xa4{JP\xf6j\xa3\xb2\xb2\xc6b\x9f\xae\x82\xa5\xd4\xaeen\xde\x12\x16\xfb\xf6\x079\x83\xd2\xbdC\'\x93\x9e\xc3\xeb\xc7\x03\x82")
>>> len(ba)
50
>>> ba.extend(bytearray(14))
>>> ba
bytearray(b"_#\xbf\x02\xd6\x19\x0c)\xd9\x18\xaf\xb9\xa4{JP\xf6j\xa3\xb2\xb2\xc6b\x9f\xae\x82\xa5\xd4\xaeen\xde\x12\x16\xfb\xf6\x079\x83\xd2\xbdC\'\x93\x9e\xc3\xeb\xc7\x03\x82\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
>>> cfb.reset_vector()
>>>
>>> cfb.crypt_inplace(ba, False)
bytearray(b'This is a long message that needs to be encrypted.d\xd5\x99vk\x08\x1c\x82\xf0_\xb8\x8aw\x85')
>>> cfb.reset_vector()

AES-128 8-bit CFB mode

The 8-bit CFB mode is less efficient than the default (128-bit) CFB mode. But its advantage is it can encrypt or decrypt data byte by byte. So it is easy to implement data stream encryption or decryption with it.

>>> from cryptocfb import CryptoCFB
>>>
>>> key = b'0123456789abcdef'
>>> iv = bytes(reversed(key))
>>> cfb1 = CryptoCFB(key, iv, 8)
>>> cfb2 = CryptoCFB(key, iv, 8)
>>>
>>> plain = b'This is a long message that needs to be encrypted.'
>>> cipher = bytearray()
>>> decrypted_plain = bytearray()
>>>
>>> for i in range(len(plain)):
...     cb = cfb1.encrypt(plain[i : i + 1])
...     cipher.extend(cb)
...     db = cfb2.decrypt(cb)
...     decrypted_plain.extend(db)
...
>>> cipher
bytearray(b'_\xf7+\xf1`4\x88\x88\x88\xba\xfb\x87\xe0_Lc\xbf\xc9AM\x95\xf3\x8dR\x1b>~\x91\x00\x9a\x1f\t\x99$\x02\xfbC\x810_J\x89\x9a\x81>Z\xe6\x9f^H')
>>> decrypted_plain
bytearray(b'This is a long message that needs to be encrypted.')

During transmission, if any encrypted data byte is corrupted, the result decrypted data will be corrupted as well. By the nature of CFB mode, the communication will recover by it self after several garbage bytes (17 bytes in the case below). This self-recovery behaviour makes it suitable for serial communication where data corruption could happen.

>>> from cryptocfb import CryptoCFB
>>>
>>> key = b'0123456789abcdef'
>>> iv = bytes(reversed(key))
>>> cfb1 = CryptoCFB(key, iv, 8)
>>> cfb2 = CryptoCFB(key, iv, 8)
>>>
>>> plain = b'This is a long message that needs to be encrypted.'
>>> cipher = bytearray()
>>> decrypted_plain = bytearray()
>>>
>>> for i in range(len(plain)):
...     cb = cfb1.encrypt(plain[i : i + 1])
...     if i == 10:
...         cb[0] ^= 0x01
...     cipher.extend(cb)
...     db = cfb2.decrypt(cb)
...     decrypted_plain.extend(db)
...
>>> cipher
bytearray(b'_\xf7+\xf1`4\x88\x88\x88\xba\xfa\x87\xe0_Lc\xbf\xc9AM\x95\xf3\x8dR\x1b>~\x91\x00\x9a\x1f\t\x99$\x02\xfbC\x810_J\x89\x9a\x81>Z\xe6\x9f^H')
>>> decrypted_plain
bytearray(b'This is a m\x12\xa2;\xf5\xdb\xbd\x10\xa0\xc2\xbd\xa2\xa4\x05V\xc2\xdd needs to be encrypted.')
You might also like...
PyCrypter , A Tool To Encrypt/Decrypt Text/Code With Ease And Safe Using Password !

PyCrypter PyCrypter , A Tool To Encrypt/Decrypt Text/Code With Ease And Safe Using Password ! Requirements pyfiglet And colorama Usage First Clone The

Enchpyter, is able to encrypt and decrypt words as you determine, of course, according to the alphabet.

Enchpyter is a program do encrypt and decrypt any word you want (just letters). You enter how many letters jumps and write the word, so, the program encrypt for you in seconds.

Vaulty - Encrypt/Decrypt with ChaCha20-Poly1305

Vaulty Encrypt/Decrypt with ChaCha20-Poly1305 Vaulty is an extremely lightweight encryption/decryption tool which uses ChaCha20-Poly1305 to provide 25

This program can encrypt/ decrypt any string

Ceasar_cipher Hey this is J0ey, this program is a very basic Caesar cipher encoder/decoder. In order to use this program, you will need to have Python

Simple encryption/decryption utility using Pycryptodome module. Working with AES and RSA algorithms.

EncypherUtil Simple encryption/decryption utility using PyCryptodome module. Working with AES and RSA algorithms. THIS UTILITY IS NOT LICENSED AS CRYP

A hybrid(AES + RSA) encryptor in python.

python-file-encryptor A hybrid(AES + RSA) encryptor in python. Tasted on Windows and Linux(Kali). Install Requirements Use the package manager pip to

A python script for AES Angecryption in Steganography

Angecryption is an encryption or an decryption result from a file to create an other file with the same / or not type.

Kyrie Eleison - The best and unique way to encrypt some data or a file safely
Kyrie Eleison - The best and unique way to encrypt some data or a file safely

Encrypt your important data and files easily and safely with Kyrie Eleison.

This is an experimental AES-encrypted RPC API for ESP 8266.

URPC This is an experimental AES-encrypted RPC API for ESP 8266. Usage The server folder contains a sample ESP 8266 project. Simply set the values in

Owner
Quan Lin
Quan Lin
Powerful Tool to encrypt and decrypt files using AES.

AEScryptor Tool Description Encrypt and Decrypt files with AES-128 (16bytes key). AES mode = CFB (cipher Feedback) security = super safe! Usage [1] Ch

null 5 Jan 12, 2022
A Python Tool to encrypt all types of files using AES and XOR Algorithm.

DataShield This project intends to protect user’s data, it stores files in encrypted format in device provided the passcode and path of the file. AES

ADITYA SHINDE 4 Dec 20, 2021
Simple python program to encrypt files with AES-256 encryption

simple-enc Simple python program to encrypt files with AES-256 encryption Setup First install "pyAesCrypt" using pip. Thats it! Optionally you can add

Hashm 2 Jan 19, 2022
Hide secret texts inside an image, optionally encrypt them with a password using AES-256.

Hide secret texts/messages inside an image. You can optionally encrypt your texts with a password using AES-256 before encoding into the image.

Teja Swaroop 97 Dec 29, 2022
obj-encrypt is an encryption library based on the AES-256 algorithm.

obj-encrypt is an encryption library based on the AES-256 algorithm. It uses Python objects as the basic unit, which can convert objects into binary ciphertext and support decryption. Objects encrypted with obj-encrypt support TCP communication, database storage, and more.

Cyberbolt 2 May 4, 2022
A short code in python, Enchpyter, is able to encrypt and decrypt words as you determine, of course

Enchpyter Enchpyter is a program do encrypt and decrypt any word you want (just letters). You enter how many letters jumps and write the word, so, the

João Assalim 2 Dec 9, 2021
Encrypt decrypt files - Programmed in Python | PySimpleGUI

Crypter Programmed in Python | PySimpleGUI If you like it give it a star How it works Crypter program use Fernet for encryption. Fernet guarantees tha

Adrijan 11 Jun 18, 2022
Encrypt your code without a worry. Stark utilizes the base64, hashlib and Crypto lib to encrypt your code which cannot be decrypted with any online tools.

Stark Encrypt your code without a worry. Stark utilizes the base64, hashlib and Crypto lib to encrypt your code which cannot be decrypted with any onl

cliphd 3 Sep 10, 2021
This program can encrypt and decrypt your files so that they can no longer be identified.

File_Cryptographer Table of Contents: About the Program Features Requirements Preview Credits Reach Me See Also About the Program: with this program,

Sina.f 6 Nov 20, 2022
Small utility to encrypt and decrypt messages

Safe Safe is a small utility to encrypt and decrypt messages using a pair of public and private keys. Installation You need to have GPG installed in y

Gustavo Eguez 2 Dec 21, 2021