mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-26 09:46:17 -04:00
Merge branch 'master' into take-nth-bytes
This commit is contained in:
commit
7cc3e5804b
9 changed files with 499 additions and 10 deletions
|
@ -1579,19 +1579,31 @@ DES uses a key length of 8 bytes (64 bits).`,
|
|||
from Crypto.Cipher import Blowfish
|
||||
import binascii
|
||||
|
||||
input_data = b"The quick brown fox jumps over the lazy dog."
|
||||
# Blowfish cipher parameters - key, mode, iv, segment_size, nonce
|
||||
key = binascii.unhexlify("0011223344556677")
|
||||
iv = binascii.unhexlify("0000000000000000")
|
||||
mode = Blowfish.MODE_CBC
|
||||
kwargs = {}
|
||||
iv = binascii.unhexlify("ffeeddccbbaa9988")
|
||||
if mode in [Blowfish.MODE_CBC, Blowfish.MODE_CFB, Blowfish.MODE_OFB]:
|
||||
kwargs = {"iv": iv}
|
||||
if mode == Blowfish.MODE_CFB:
|
||||
kwargs["segment_size"] = 64
|
||||
if mode == Blowfish.MODE_CTR:
|
||||
nonce = binascii.unhexlify("0000000000000000")
|
||||
nonce = nonce[:7]
|
||||
kwargs["nonce"] = nonce
|
||||
|
||||
cipher = Blowfish.new(key, mode, **kwargs)
|
||||
|
||||
# Input data and padding
|
||||
input_data = b"The quick brown fox jumps over the lazy dog."
|
||||
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
|
||||
# Encrypted text
|
||||
cipher_text = cipher.encrypt(input_data)
|
||||
|
||||
cipher_text = binascii.hexlify(cipher_text).decode("UTF-8")
|
||||
|
||||
print("Encrypted: {}".format(cipher_text))
|
||||
|
|
123
tests/operations/tests/DropNthBytes.mjs
Normal file
123
tests/operations/tests/DropNthBytes.mjs
Normal file
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* @author Oshawk [oshawk@protonmail.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
/**
|
||||
* Drop nth bytes tests
|
||||
*/
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Drop nth bytes: Nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Nothing (apply to each line)",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic single line",
|
||||
input: "0123456789",
|
||||
expectedOutput: "1235679",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic single line (apply to each line)",
|
||||
input: "0123456789",
|
||||
expectedOutput: "1235679",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex single line",
|
||||
input: "0123456789",
|
||||
expectedOutput: "01234678",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex single line (apply to each line)",
|
||||
input: "0123456789",
|
||||
expectedOutput: "01234678",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic multi line",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "123\n5689",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic multi line (apply to each line)",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "123\n678",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex multi line",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "012345679",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex multi line (apply to each line)",
|
||||
input: "012345\n6789ab",
|
||||
expectedOutput: "01234\n6789a",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, true],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
63
tests/operations/tests/IPv6Transition.mjs
Normal file
63
tests/operations/tests/IPv6Transition.mjs
Normal file
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* IPv6Transition tests.
|
||||
*
|
||||
* @author jb30795
|
||||
*
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "IPv6 Transition: IPv4 to IPv6",
|
||||
input: "198.51.100.7",
|
||||
expectedOutput: "6to4: 2002:c633:6407::/48\nIPv4 Mapped: ::ffff:c633:6407\nIPv4 Translated: ::ffff:0:c633:6407\nNat 64: 64:ff9b::c633:6407",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, false],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: IPv4 /24 Range to IPv6",
|
||||
input: "198.51.100.0/24",
|
||||
expectedOutput: "6to4: 2002:c633:6400::/40\nIPv4 Mapped: ::ffff:c633:6400/120\nIPv4 Translated: ::ffff:0:c633:6400/120\nNat 64: 64:ff9b::c633:6400/120",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [false, false],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: IPv4 to IPv6 Remove headers",
|
||||
input: "198.51.100.7",
|
||||
expectedOutput: "2002:c633:6407::/48\n::ffff:c633:6407\n::ffff:0:c633:6407\n64:ff9b::c633:6407",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, true],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: IPv6 to IPv4",
|
||||
input: "64:ff9b::c633:6407",
|
||||
expectedOutput: "IPv4: 198.51.100.7",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, false],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: MAC to EUI-64",
|
||||
input: "a1:b2:c3:d4:e5:f6",
|
||||
expectedOutput: "EUI-64 Interface ID: a3b2:c3ff:fed4:e5f6",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
Loading…
Add table
Add a link
Reference in a new issue