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_index– integer; 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 datasetnumber_of_samples– integer; how many testing data should be generatedsave_file– boolean (default: False); save the generated data to file if it is Truefilename– string (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_index– integer; 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 datasetnumber_of_samples– integer; how many testing data should be generatednumber_of_blocks_in_one_sample– integer; how many blocks should be generated in one test sequencesave_file– boolean (default: False); save the generated data to file if it is Truefilename– string (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_index– integer; 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 datasetnumber_of_samples– integer; how many testing data should be generatednumber_of_blocks_in_one_sample– integer; how many blocks should be generated in one test sequencesave_file– boolean (default: False); save the generated data to file if it is Truefilename– string (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_index– integer; 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 datasetnumber_of_samples– integer; how many testing data should be generatedratio– integer (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_file– boolean (default: False); save the generated data to file if it is Truefilename– string (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_index– integer; 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 datasetnumber_of_samples– integer; how many testing data should be generatedratio– integer (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 inputssave_file– boolean (default: False); save the generated data to file if it is Truefilename– string (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_index– integer; 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 datasetnumber_of_samples– integer; how many testing data should be generatednumber_of_blocks_in_one_sample– integer how many blocks should be generated in one test sequencesave_file– boolean (default: False); save the generated data to file if it is Truefilename– string (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:
EnumAn 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)¶