add switch for each function of randomlooking check
This commit is contained in:
@@ -1,6 +1,31 @@
|
|||||||
#ifndef _MESA_STS_H_
|
#ifndef _MESA_STS_H_
|
||||||
#define _MESA_STS_H_
|
#define _MESA_STS_H_
|
||||||
|
|
||||||
|
#define STS_RANDOM_JUDGE_NUM 15
|
||||||
|
|
||||||
|
#define STS_SET_FLAG(flag, idx) (flag |= (1 << idx))
|
||||||
|
#define STS_TEST_FLAG(flag, idx) (flag & (1 << idx))
|
||||||
|
|
||||||
|
enum sts_random_judge_list_idx
|
||||||
|
{
|
||||||
|
STS_FREQUENCY = 0,
|
||||||
|
STS_BLOCK_FREQUENCY,
|
||||||
|
STS_CUMULATIVE_SUMS,
|
||||||
|
STS_RUNS,
|
||||||
|
STS_LONGEST_RUN,
|
||||||
|
STS_RANK,
|
||||||
|
STS_NON_OVERLAPPING_TEMPLATE_MATCHING,
|
||||||
|
STS_OVERLAPPING_TEMPLATE_MATCHING,
|
||||||
|
STS_UNIVERSAL,
|
||||||
|
STS_RANDOM_EXCURSIONS,
|
||||||
|
STS_RANDOM_EXCURSIONS_VARIANT,
|
||||||
|
STS_POKER_DETECT,
|
||||||
|
STS_RUNS_DISTRIBUTION,
|
||||||
|
STS_SELF_CORRELATION,
|
||||||
|
STS_BINARY_DERIVATE,
|
||||||
|
STS_RANDOM_IDX_MAX
|
||||||
|
};
|
||||||
|
|
||||||
struct sts_result {
|
struct sts_result {
|
||||||
unsigned char frequency;
|
unsigned char frequency;
|
||||||
unsigned char block_frequency;
|
unsigned char block_frequency;
|
||||||
@@ -23,7 +48,7 @@ struct sts_result {
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result);
|
int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result, unsigned int random_judge_switch_flag);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "include/stat_fncs.h"
|
#include "include/stat_fncs.h"
|
||||||
#include "mesa_sts.h"
|
#include "mesa_sts.h"
|
||||||
|
|
||||||
int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result)
|
int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result, unsigned int random_judge_switch_flag)
|
||||||
{
|
{
|
||||||
TP tp;
|
TP tp;
|
||||||
tp.n = datalen;
|
tp.n = datalen;
|
||||||
@@ -25,25 +25,87 @@ int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_resu
|
|||||||
bitsRead = 0;
|
bitsRead = 0;
|
||||||
done = 0;
|
done = 0;
|
||||||
done = convertToBits((BYTE*)data,datalen,tp.n,&num_0s,&num_1s,&bitsRead,epsilon);
|
done = convertToBits((BYTE*)data,datalen,tp.n,&num_0s,&num_1s,&bitsRead,epsilon);
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_FREQUENCY))
|
||||||
|
{
|
||||||
result->frequency = Frequency(tp.n,epsilon);
|
result->frequency = Frequency(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_BLOCK_FREQUENCY))
|
||||||
|
{
|
||||||
result->block_frequency = BlockFrequency(tp.blockFrequencyBlockLength, tp.n,epsilon);
|
result->block_frequency = BlockFrequency(tp.blockFrequencyBlockLength, tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_CUMULATIVE_SUMS))
|
||||||
|
{
|
||||||
result->cumulative_sums = CumulativeSums(tp.n,epsilon);
|
result->cumulative_sums = CumulativeSums(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_RUNS))
|
||||||
|
{
|
||||||
result->runs = Runs(tp.n,epsilon);
|
result->runs = Runs(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_LONGEST_RUN))
|
||||||
|
{
|
||||||
result->longest_run = LongestRunOfOnes(tp.n,epsilon);
|
result->longest_run = LongestRunOfOnes(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_RANK))
|
||||||
|
{
|
||||||
result->rank = Rank(tp.n,epsilon);
|
result->rank = Rank(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
//result->discrete_fourier_transform = DiscreteFourierTransform(tp.n,epsilon);//cost too much time
|
//result->discrete_fourier_transform = DiscreteFourierTransform(tp.n,epsilon);//cost too much time
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_NON_OVERLAPPING_TEMPLATE_MATCHING))
|
||||||
|
{
|
||||||
result->non_overlapping_template_matching = NonOverlappingTemplateMatchings(tp.nonOverlappingTemplateBlockLength, tp.n,epsilon);
|
result->non_overlapping_template_matching = NonOverlappingTemplateMatchings(tp.nonOverlappingTemplateBlockLength, tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_OVERLAPPING_TEMPLATE_MATCHING))
|
||||||
|
{
|
||||||
result->overlapping_template_matching = OverlappingTemplateMatchings(tp.overlappingTemplateBlockLength, tp.n,epsilon);
|
result->overlapping_template_matching = OverlappingTemplateMatchings(tp.overlappingTemplateBlockLength, tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_UNIVERSAL))
|
||||||
|
{
|
||||||
result->universal = Universal(tp.n,epsilon);
|
result->universal = Universal(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
//result->approximate_entropy = ApproximateEntropy(tp.approximateEntropyBlockLength, tp.n,epsilon);//cost too much time
|
//result->approximate_entropy = ApproximateEntropy(tp.approximateEntropyBlockLength, tp.n,epsilon);//cost too much time
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_RANDOM_EXCURSIONS))
|
||||||
|
{
|
||||||
result->random_excursions = RandomExcursions(tp.n,epsilon);
|
result->random_excursions = RandomExcursions(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_RANDOM_EXCURSIONS_VARIANT))
|
||||||
|
{
|
||||||
result->random_excursions_variant = RandomExcursionsVariant(tp.n,epsilon);
|
result->random_excursions_variant = RandomExcursionsVariant(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
//result->serial = Serial(tp.serialBlockLength,tp.n,epsilon);//cost too much time
|
//result->serial = Serial(tp.serialBlockLength,tp.n,epsilon);//cost too much time
|
||||||
//sresult->linear_complexity = LinearComplexity(tp.linearComplexitySequenceLength, tp.n,epsilon);//cost too much time
|
//sresult->linear_complexity = LinearComplexity(tp.linearComplexitySequenceLength, tp.n,epsilon);//cost too much time
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_POKER_DETECT))
|
||||||
|
{
|
||||||
result->poker_detect = PokerDetect(tp.PokerDetectMLength,tp.n,epsilon);
|
result->poker_detect = PokerDetect(tp.PokerDetectMLength,tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_RUNS_DISTRIBUTION))
|
||||||
|
{
|
||||||
result->runs_distribution = RunsDistribution(tp.n,epsilon);
|
result->runs_distribution = RunsDistribution(tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_SELF_CORRELATION))
|
||||||
|
{
|
||||||
result->self_correlation = SelfCorrelation(tp.SelfCorrelationDLength,tp.n,epsilon);
|
result->self_correlation = SelfCorrelation(tp.SelfCorrelationDLength,tp.n,epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STS_TEST_FLAG(random_judge_switch_flag, STS_BINARY_DERIVATE))
|
||||||
|
{
|
||||||
result->binary_derivative = BinaryDerivate(tp.BinaryDerivateKLength,tp.n,epsilon,tp.n);//this function will change the value of epsilon, must be the last one
|
result->binary_derivative = BinaryDerivate(tp.BinaryDerivateKLength,tp.n,epsilon,tp.n);//this function will change the value of epsilon, must be the last one
|
||||||
|
}
|
||||||
|
|
||||||
free(epsilon);
|
free(epsilon);
|
||||||
epsilon = NULL;
|
epsilon = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user