Skip to content

TwoFish implementation in python with vector tests.

License

Notifications You must be signed in to change notification settings

K-Czaplicki/TwoFish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Twofish Python Implementation

This project implements the Twofish symmetric key block cipher in Python. Twofish is a symmetric key block cipher with a block size of 128 bits and key sizes up to 256 bits. The cipher was designed by Bruce Schneier, John Kelsey, Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson and was one of the five finalists of the Advanced Encryption Standard (AES) contest, but it was not selected for standardization.

Implementation Details

While implementing functions for this project we strictly followed the steps from the official paper titled: Twofish: A 128-Bit Block Cipher. Our implementation supports both ECB (Electronic Codebook) and CBC (Cipher Block Chaining) modes of operation.

Usage

To use this implementation in your Python projects, simply import the necessary functions from the provided modules. Ensure that you have Python installed on your system.

Clone the repo:

git clone https://github.com/K-Czaplicki/TwoFish.git

Example usage:

import sys
sys.path.append('/path/to/TwoFish')
from TwoFish import *

key = text_To_Hex("This is a key")
plain = text_To_Hex("This is an example")
mode = "ECB"

# Encrypt
ciphertext = TwoFish_encrypt(plain, key, mode)

# Decrypt
decoded_plaintext = hex_To_Text(TwoFish_decrypt(ciphertext, key, mode))

print("Ciphertext: ", ciphertext)
print("Decoded plaintext:", decoded_plaintext)

The result of running this example should be:

Ciphertext:  533FC35A0030003689E7D1D9F2E6781A6F5555EFC8AB9531A103EC74E406C969
Decoded plaintext: This is an example

Testing

The implementation has been thoroughly tested using test vectors provided by the official paper. Test vectors are sets of known inputs and their corresponding outputs, used to verify the correctness of the implementation.

Authors

License

This project is licensed under the MIT License.