Dataset generator

class DatasetGenerator(cipher)

Bases: object

generate_avalanche_dataset(input_index, number_of_samples, save_file=False, filename='')

Generate the avalanche dataset.

INPUT:

  • input_indexinteger; the index of inputs to generate testing data. For example, inputs=[key, plaintest], input_index=0 means it will generate the key avalanche dataset. If input_index=1 means it will generate the plaintext avalanche dataset

  • number_of_samplesinteger; how many testing data should be generated

  • save_fileboolean (default: False); save the generated data to file if it is True

  • filenamestring (default: ``); the file name to save the generated data

OUTPUT:

  • dataset – output the dataset in bit_stream format

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.statistical_tests.dataset_generator import DatasetGenerator
sage: dataset_generator = DatasetGenerator(SpeckBlockCipher(number_of_rounds=3))
sage: dataset_generator.generate_avalanche_dataset(input_index=0, number_of_samples=2)  # random
[array([0, 1, 0, ..., 0, 0, 0], dtype=uint8),
 ...
 array([6, 237, 14, ..., 0, 0, 0], dtype=uint8)]
generate_cbc_dataset(input_index, number_of_samples, number_of_blocks_in_one_sample, save_file=False, filename='')

Generate the CBC dataset.

INPUT:

  • input_indexinteger; the index of inputs to generate testing data. For example, inputs=[key, plaintest], input_index=0 means it will generate the key CBC dataset. if input_index=1 means it will generate the plaintext CBC dataset

  • number_of_samplesinteger; how many testing data should be generated

  • number_of_blocks_in_one_sampleinteger; how many blocks should be generated in one test sequence

  • save_fileboolean (default: False); save the generated data to file if it is True

  • filenamestring (default: ``); the file name to save the generated data

OUTPUT:

  • dataset – output the dataset in bit_stream format

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.statistical_tests.dataset_generator import DatasetGenerator
sage: dataset_generator = DatasetGenerator(SpeckBlockCipher(number_of_rounds=3))
sage: dataset_generator.generate_cbc_dataset(input_index=0, number_of_samples=2, number_of_blocks_in_one_sample=10) # random
[array([163,  27,  29, 156, ...,  72,  33,  37,  90], dtype=uint8),
 ...
 array([ 80, 178,  59,  25, ..., 124,  47, 118, 221], dtype=uint8)]
generate_correlation_dataset(input_index, number_of_samples, number_of_blocks_in_one_sample, save_file=False, filename='')

Generate the correlation dataset.

INPUT:

  • input_indexinteger; the index of inputs to generate testing data. For example, inputs=[key, plaintest], input_index=0 means it will generate the key correlation dataset. If input_index=1 means it will generate the plaintext correlation dataset

  • number_of_samplesinteger; how many testing data should be generated

  • number_of_blocks_in_one_sampleinteger; how many blocks should be generated in one test sequence

  • save_fileboolean (default: False); save the generated data to file if it is True

  • filenamestring (default: ``); the file name to save the generated data

OUTPUT:

  • dataset – output the dataset in bit_stream format

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.statistical_tests.dataset_generator import DatasetGenerator
sage: dataset_generator = DatasetGenerator(SpeckBlockCipher(number_of_rounds=3))
sage: dataset_generator.generate_correlation_dataset(input_index=0, number_of_samples=2, number_of_blocks_in_one_sample=10)  # random
[array([163,  27,  29, 156, ...,  72,  33,  37,  90], dtype=uint8),
 ...
 array([ 80, 178,  59,  25, ..., 124,  47, 118, 221], dtype=uint8)]
generate_high_density_dataset(input_index, number_of_samples, ratio=1, save_file=False, filename='')

Generate the high density dataset.

INPUT:

  • input_indexinteger; the index of inputs to generate testing data. For example, inputs=[key, plaintest], input_index=0 means it will generate the key high density dataset. if input_index=1 means it will generate the plaintext high density dataset

  • number_of_samplesinteger; how many testing data should be generated

  • ratiointeger (default: 1); the ratio of weight 2 (that is, two 1 in the input) as high density inputs, range in [0, 1]. For exmaple, if ratio = 0.5, means half of the weight 2 high density inputs will be taken as inputs.

  • save_fileboolean (default: False); save the generated data to file if it is True

  • filenamestring (default: ``); the file name to save the generated data

OUTPUT:

  • dataset – output the dataset in bit_stream format

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.statistical_tests.dataset_generator import DatasetGenerator
sage: dataset_generator = DatasetGenerator(SpeckBlockCipher(number_of_rounds=3))
sage: dataset_generator.generate_high_density_dataset(input_index=0, number_of_samples=2, ratio=0.5)  # random
[array([163,  27,  29, 156, ...,  72,  33,  37,  90], dtype=uint8),
 ...
 array([ 80, 178,  59,  25, ..., 124,  47, 118, 221], dtype=uint8)]
generate_low_density_dataset(input_index, number_of_samples, ratio=1, save_file=False, filename='')

Generate the low density dataset.

INPUT:

  • input_indexinteger; the index of inputs to generate testing data. For example, inputs=[key, plaintest], input_index=0 means it will generate the key low density dataset. if input_index=1 means it will generate the plaintext low density dataset

  • number_of_samplesinteger; how many testing data should be generated

  • ratiointeger (default: 1); the ratio of weight 2 (that is, two 1 in the input) as low density inputs, range in [0, 1]. For example, if ratio = 0.5, means half of the weight 2 low density inputs will be taken as inputs

  • save_fileboolean (default: False); save the generated data to file if it is True

  • filenamestring (default: ``); the file name to save the generated data

OUTPUT:

  • dataset – output the dataset in bit_stream format

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.statistical_tests.dataset_generator import DatasetGenerator
sage: dataset_generator = DatasetGenerator(SpeckBlockCipher(number_of_rounds=3))
sage: dataset_generator.generate_low_density_dataset(input_index=0, number_of_samples=2, ratio=0.5)  # random
[array([163,  27,  29, 156, ...,  72,  33,  37,  90], dtype=uint8),
 ...
 array([ 80, 178,  59,  25, ..., 124,  47, 118, 221], dtype=uint8)]
generate_random_dataset(input_index, number_of_samples, number_of_blocks_in_one_sample, save_file=False, filename='')

Generate the random dataset.

INPUT:

  • input_indexinteger; the index of inputs to generate testing data. For example, inputs=[key, plaintest], input_index=0 means it will generate the key random dataset. if input_index=1 means it will generate the plaintext random dataset

  • number_of_samplesinteger; how many testing data should be generated

  • number_of_blocks_in_one_sampleinteger how many blocks should be generated in one test sequence

  • save_fileboolean (default: False); save the generated data to file if it is True

  • filenamestring (default: ``); the file name to save the generated data

OUTPUT:

  • dataset – output the dataset in bit_stream format

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.statistical_tests.dataset_generator import DatasetGenerator
sage: dataset_generator = DatasetGenerator(SpeckBlockCipher(number_of_rounds=3))
sage: dataset_generator.generate_random_dataset(input_index=0, number_of_samples=2, number_of_blocks_in_one_sample=10) # random
[array([163,  27,  29, 156, ...,  72,  33,  37,  90], dtype=uint8),
 ...
 array([ 80, 178,  59,  25, ..., 124,  47, 118, 221], dtype=uint8)]
get_cipher_outputs_for_cbc_dataset(input_index, number_of_blocks_in_one_sample, number_of_samples)
get_cipher_outputs_for_correlation_dataset(input_index, inputs_fixed, number_of_blocks_in_one_sample, number_of_samples)
get_cipher_outputs_for_density_dataset(input_index, inputs_density, number_of_samples)
class DatasetType(value)

Bases: Enum

An enumeration.

avalanche = 'avalanche'
cbc = 'cipher_block_chaining_mode'
correlation = 'correlation'
high_density = 'high_density'
low_density = 'low_density'
random = 'random'
get_low_density_sequences(bit_length)
set_testing_data_amount(number_of_blocks_in_one_sample, number_of_samples)