From 9872578d5139ce32035184ca6503820f31ae8fff Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Tue, 1 Oct 2019 23:20:27 +0100 Subject: [PATCH] Add reference Python script --- tests/operations/tests/Crypt.mjs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index 7bd9ca403..ae158e785 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -1372,8 +1372,27 @@ DES uses a key length of 8 bytes (64 bits).`, } ], }, + /* The following expectedOutputs are generated with this Python script with pyCryptoDome + from Crypto.Cipher import Blowfish + import binascii - // The following expectedOutputs are generated with pyCryptoDome + input_data = b"The quick brown fox jumps over the lazy dog." + key = binascii.unhexlify("0011223344556677") + iv = binascii.unhexlify("0000000000000000") + mode = Blowfish.MODE_CBC + + if mode == Blowfish.MODE_ECB or mode == Blowfish.MODE_CBC: + padding_len = 8-(len(input_data) & 7) + for i in range(padding_len): + input_data += bytes([padding_len]) + + cipher = Blowfish.new(key, mode) # set iv, nonce, segment_size etc. here + cipher_text = cipher.encrypt(input_data) + + cipher_text = binascii.hexlify(cipher_text).decode("UTF-8") + + print("Encrypted: {}".format(cipher_text)) +*/ { name: "Blowfish Encrypt: ECB, ASCII", input: "The quick brown fox jumps over the lazy dog.",