Title: | Statistical Tests for Cryptographic Randomness |
---|---|
Description: | Performs cryptographic randomness tests on a sequence of random integers or bits. Included tests are greatest common divisor, birthday spacings, book stack, adaptive chi-square, topological binary, and three random walk tests (Ryabko and Monarev, 2005) <doi:10.1016/j.jspi.2004.02.010>. Tests except greatest common divisor and birthday spacings are not covered by standard test suites. In addition to the chi-square goodness-of-fit test, results of Anderson-Darling, Kolmogorov-Smirnov, and Jarque-Bera tests are also generated by some of the cryptographic randomness tests. |
Authors: | Haydar Demirhan |
Maintainer: | Haydar Demirhan <[email protected]> |
License: | GPL-3 |
Version: | 1.2.7 |
Built: | 2025-02-17 05:01:06 UTC |
Source: | https://github.com/cran/CryptRndTest |
Performs cryptographic randomness tests on a sequence of random integers or bits. Included tests are greatest common divisor, birthday spacings, book stack, adaptive chi-square, topological binary, and three random walk tests. Tests except greatest common divisor and birthday spacings are not covered by standard test suites. In addition to the chi-square goodness-of-fit test, results of Anderson-Darling, Kolmogorov-Smirnov, and Jarque-Bera tests are also generated by some of the cryptographic randomness tests. Additionally, it includes functions for the calculation of greatest common divisor, the Stirling numbers of the second kind, critical value of the topological binary test, and base conversions from base 2 to 10 and vice versa.
Package: | CryptRndTest |
Type: | Package |
Version: | 1.2.7 |
Date: | 2022-04-20 |
License: | GPL-3 |
To test statistical randomness of cryptographic randomness use functions birthday.spacings
and GCD.test
for testing sequences of integers, functions adaptive.chi.square
and book.stack
for testing sequences of integers or bits, and use functions random.walk.tests
and topological.binary
for testing sequences of bits. The function random.walk.tests
performs random walk-excursion, random walk-expansion, and random walk-height tests.
Additionally, use the function GCD.q
to compute greatest common divisor (GCD), the number of iterations required to find GCD, and the sequence of partial quotients for two integers. Use the function GCD
to compute GCD and the number iterations required to find GCD, recursively. Use the function GCD.big
to compute GCD, the number iterations required to find GCD, and the sequence of partial quotients for two big integers. Use the function Strlng2
to compute the Stirling numbers of the second kind in an approximate manner when the inputs are large. Use the function TBT.criticalValue
to compute the critical value for the topological binary test at a given level of significance. Use the function toBaseTwo
to convert integers (including big integers) from base 10 to 2. Use the function toBaseTen
to convert binary sequences (including long binary sequences) from base 2 to 10.
Acknowledgement: The package CryptRndTest is based upon work supported by The Scientific and Technological Research Council of Turkey (TUBITAK) under Grant No. 114F249 of ARDEB-3001 grant.
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Alcover, P.M., Guillamon, A., Ruiz, M.C., A new randomness test for bit sequences. Informatica (2013), 24(3), 339–356.
Bleick, W.W., Wang, P.C.C., Asymptotics of Stirling Numbers of the Second Kind. Proceedings of the American Mathematical Society (1974), 42(2), 575–580.
Doganaksoy, A., Calik, C., Sulak, F., Turan, M.S., New randomness tests using random walk, In: National Cryptology Symposium II, (2006), Ankara, Turkey.
Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3).
Ryabko, B.Ya., Monarev, V.A., Using information theory approach to randomness testing. Journal of Statistical Planning and Inference (2005), 133, 95–110.
Ryabko, B.Ya., Stognienko, V.S., Shokin Yu.I., A new test for randomness and its application to some cryptographic problems. Journal of Statistical Planning and Inference (2004), 123, 365–376.
Temme, N.M., Asymptotic estimates of Stirling numbers. Studies in Applied Mathematics (1993), 89, 233–243.
adaptive.chi.square
, birthday.spacings
, book.stack
, GCD.test
, GCD
, GCD.q
, GCD.big
, random.walk.tests
, topological.binary
, Strlng2
, Stirling2
# ----- General settings --- RNGkind(kind = "Super-Duper") B=8 # Bit length is 8. k=2000 # Generate 20000 integers. alpha=0.05 # ----- Adaptive chi-square ----- A=0 A=round(runif(k,0,(2^B-1))) S=2 # Divide alphabet to two sub-sets. test1=adaptive.chi.square(x=A, B, S, alpha, bit = FALSE) print(test1) # ----- Birthday Spacings ----- m=16 # Number of birthdays is 16. n=2^B # Length of year is 256. lambda=(m^3)/(4*n) x=round(runif(k,0,(2^B-1))) test2=birthday.spacings(x, m, n, alpha, lambda, num.class=10) print(test2) # ----- Book Stack ----- n=B*(2^(B/2)) # Number of required bits. N=n/B # Number of integers to be generated. A=0 A=round(runif(N,0,(2^B-1))) K=2 # Divide alphabet to two sub-sets. test3=book.stack(x=A, B, k = K, alpha, bit = FALSE) print(test3) # ----- Toplogical Binary Test ----- dat=round(runif(k,0,(2^B-1))) x=sfsmisc::digitsBase(dat, base= 2, B) #Convert to base 2 critical.value=150 #Obtained for B=8 test4=topological.binary(x, B, alpha, critical.value) print(test4) # ----- Other Functions ----- # ----- GCD ----- result=GCD(45,2) print(result) result=GCD(321235,25521) print(result) # ----- Striling 2 ----- Strlng2(1500,410,log=TRUE) # Large values of n and k
# ----- General settings --- RNGkind(kind = "Super-Duper") B=8 # Bit length is 8. k=2000 # Generate 20000 integers. alpha=0.05 # ----- Adaptive chi-square ----- A=0 A=round(runif(k,0,(2^B-1))) S=2 # Divide alphabet to two sub-sets. test1=adaptive.chi.square(x=A, B, S, alpha, bit = FALSE) print(test1) # ----- Birthday Spacings ----- m=16 # Number of birthdays is 16. n=2^B # Length of year is 256. lambda=(m^3)/(4*n) x=round(runif(k,0,(2^B-1))) test2=birthday.spacings(x, m, n, alpha, lambda, num.class=10) print(test2) # ----- Book Stack ----- n=B*(2^(B/2)) # Number of required bits. N=n/B # Number of integers to be generated. A=0 A=round(runif(N,0,(2^B-1))) K=2 # Divide alphabet to two sub-sets. test3=book.stack(x=A, B, k = K, alpha, bit = FALSE) print(test3) # ----- Toplogical Binary Test ----- dat=round(runif(k,0,(2^B-1))) x=sfsmisc::digitsBase(dat, base= 2, B) #Convert to base 2 critical.value=150 #Obtained for B=8 test4=topological.binary(x, B, alpha, critical.value) print(test4) # ----- Other Functions ----- # ----- GCD ----- result=GCD(45,2) print(result) result=GCD(321235,25521) print(result) # ----- Striling 2 ----- Strlng2(1500,410,log=TRUE) # Large values of n and k
Performs Adaptive Chi-Square test of Ryabko et al.(2004) to evaluate the randomness of an RNG.
adaptive.chi.square(x, B, S, alpha = 0.05, prop=0.5, bit=FALSE)
adaptive.chi.square(x, B, S, alpha = 0.05, prop=0.5, bit=FALSE)
x |
a vector or matrix that includes random data. See details for further information. |
B |
the length of words (B-bit) that the chippered file will be divided into. |
S |
the number of subsets where letters of an alphabet are combined, and |
alpha |
a predetermined value of significance level with the default value of 0.05. |
prop |
a predetermined value of proportion of training data set. |
bit |
if |
It is possible to apply adaptive Chi-Square to smaller samples than that required for the regular chi-square test.
If x
contains a sequence of bits, then x
should be a matrix of x
, where
is the number of words (integers) generated by the RNG of interest. Otherwise,
x
is a x
vector of the words. Because bits will be converted to base 10 before application of the test, implementation time will be shorter with integer input.
The degrees of freedom of the resulting chi-square test is S-1
. The value of S
should be much less than .
statistic |
calculated value of the test statistic. |
p.value |
p-value of the test. |
result.acsq |
returns 0 if H0 is rejected and 1 otherwise. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Ryabko, B.Ya., Stognienko, V.S., Shokin Yu.I., A new test for randomness and its application to some cryptographic problems. Journal of Statistical Planning and Inference (2004), 123, 365–376.
RNGkind(kind = "Super-Duper") B=16 # Bit length is 16. k=5000 # Generate 5000 integers. x=0 x=round(runif(k,0,(2^B-1))) S=2 # Divide alphabet to two subsets. alpha = 0.05 test=adaptive.chi.square(x, B, S, alpha, bit =FALSE) print(test)
RNGkind(kind = "Super-Duper") B=16 # Bit length is 16. k=5000 # Generate 5000 integers. x=0 x=round(runif(k,0,(2^B-1))) S=2 # Divide alphabet to two subsets. alpha = 0.05 test=adaptive.chi.square(x, B, S, alpha, bit =FALSE) print(test)
Performs Birthday Spacings test of Marsaglia and Tsang (2002) to evaluate the randomness of an RNG. The Kolmogorov-Smirnov, Anderson-Darling, and Chi-Square tests are applied as goodness-of-fit tests.
birthday.spacings(x, m = 128, n = 2^16, alpha = 0.05, lambda, num.class = 10)
birthday.spacings(x, m = 128, n = 2^16, alpha = 0.05, lambda, num.class = 10)
x |
a vector that includes random integers. |
m |
the number of birthdays. |
n |
the length of year. |
alpha |
a predetermined value of significance level with the default value of 0.05. |
lambda |
mean of Poisson distribution that constitutes theoretical cumulative distribution function in goodness-of-fit tests. See Details section. |
num.class |
number of classes in the constructed frequency table for goodness-of-fit testing. |
This is one of the "difficult to pass tests" that RNG's that are able to pass this set of tests possibly pass most of the tests included in the Diehard Battery of Tests.
To conduct the test, birthdays are randomly chosen from a year composed of
days. When the birthdays are sorted, asymptotic distribution of the number of duplicated values among the spacings between birthdays is Poisson with mean
. For most of the cases, this formula for
lambda
is useful. However, user should check suitability of the value entered for lambda
. Note that some suitable values for and
are given by Marsaglia and Tsang (2002).
The argument num.class
should be increased along with increasing bit-length. It can be set to 5 for testing with 8-bit and to 10 for testing with 16-bit and higher.
AD.statistic |
calculated value of the test statistic of Anderson-Darling goodness-of-fit test. |
AD.pvalue |
p-value of the test of Anderson-Darling goodness-of-fit test. |
AD.result |
returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test. |
KS.statistic |
calculated value of the test statistic of Kolmogorov-Smirnov goodness-of-fit test. |
KS.pvalue |
p-value of the test of Kolmogorov-Smirnov goodness-of-fit test. |
KS.result |
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test. |
CS.statistic |
calculated value of the test statistic of Chi-Square goodness-of-fit test. |
CS.pvalue |
p-value of the test of Chi-Square goodness-of-fit test. |
CS.result |
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3).
RNGkind(kind = "L'Ecuyer-CMRG") B=16 # Bit length is 16. m=32 # Number of birthdays is 64. n=2^B # Length of year is 65536. lambda=(m^3)/(4*n) k=5000 # Generate 5000 integers. x=round(runif(k,0,(2^B-1))) alpha = 0.05 test=birthday.spacings(x, m, n, alpha, lambda, num.class=10) print(test)
RNGkind(kind = "L'Ecuyer-CMRG") B=16 # Bit length is 16. m=32 # Number of birthdays is 64. n=2^B # Length of year is 65536. lambda=(m^3)/(4*n) k=5000 # Generate 5000 integers. x=round(runif(k,0,(2^B-1))) alpha = 0.05 test=birthday.spacings(x, m, n, alpha, lambda, num.class=10) print(test)
Performs Book Stack test of Ryabko and Monarev (2005) to evaluate the randomness of an RNG. The Chi-Square test is applied as the goodness-of-fit test.
book.stack(x, B, k=2, alpha=0.05, bit=FALSE)
book.stack(x, B, k=2, alpha=0.05, bit=FALSE)
x |
a vector or matrix that includes random data. See details for further information. |
B |
the length of words (B-bit) that the chippered file will be divided. |
k |
the number of subsets that the alphabet will be divided. It should be chosen to ensure |
alpha |
a predetermined value of significance level with the default value of 0.05. |
bit |
if |
If x
contains a sequence of bits, then x
should be a matrix of x
, where
is the number of words (integers) generated by the RNG of interest. Otherwise,
x
is an x
vector of the words. Because bits will be converted to base-10 before application of the test, implementation time will be shorter with integer input.
Optimal value of
, which also represents the length of sample that is composed of B-bit words, is obtained by the optimal length of sample composed of bits (
) that is given by Ryabko and Monarev (2005) as
. For example, if
, then
and the legth of alphabet is 65536. In this case, we need to enter 4096 bits or
integers. However, under the setting
, the length of alphabet is 2^32 and we need to enter 65536. Note that it is hard to implement the test for
due to the memory overflows. Therefore, this test is applicable for smaller values of
.
In this test, because there is no asymptotic theoretical distribution introduced, only chi-square test is applied as goodness-of-fit test.
statistic |
calculated value of the test statistic. |
p.value |
p-value of the Chi-Square test. |
BS.result |
returns 0 if H0 is rejected and 1 otherwise. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Ryabko, B.Ya., Monarev, V.A., Using information theory approach to randomness testing. Journal of Statistical Planning and Inference (2005), 133, 95–110.
RNGkind(kind = "L'Ecuyer-CMRG") B=8 # Bit length is 8. n=B*(2^(B/2)) # Number of required bits. N=n/B # Number of integers to be generated. x=round(runif(N,0,(2^B-1))) k=2 # Divide alphabet to two sub-sets. alpha=0.05 test=book.stack(x, B, k, alpha, bit = FALSE) print(test)
RNGkind(kind = "L'Ecuyer-CMRG") B=8 # Bit length is 8. n=B*(2^(B/2)) # Number of required bits. N=n/B # Number of integers to be generated. x=round(runif(N,0,(2^B-1))) k=2 # Divide alphabet to two sub-sets. alpha=0.05 test=book.stack(x, B, k, alpha, bit = FALSE) print(test)
Contains functions designed for internal use only.
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
adaptive.chi.square
, birthday.spacings
, book.stack
, GCD.test
, GCD
,
GCD.q
,
GCD.big
,
random.walk.tests
, topological.binary
, Strlng2
, Stirling2
Finds the greatest common divisor (GCD) of two integers using a recursive approximation. In addition to the value of GCD, it generates the number of required iterations to find GCD.
GCD(x, y, k = 0)
GCD(x, y, k = 0)
x |
the first integer greater than zero. |
y |
the second integer greater than zero. |
k |
initial value for counting the number of steps. It must be set zero. |
k |
the number of required iterations to find GCD. |
g |
the value of greatest common divisor. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
result=GCD(4535,2451) print(result) result=GCD(35,2) print(result)
result=GCD(4535,2451) print(result) result=GCD(35,2) print(result)
Finds the greatest common divisor (GCD) of two large integers. It utilizes multiple precision floating point numbers along with the package Rmpfr. In addition to the value of GCD, it generates the number of required iterations to find GCD and the sequence of partial quotients.
GCD.big(x, y, B)
GCD.big(x, y, B)
x |
the first integer greater than zero. |
y |
the second integer greater than zero. |
B |
default precision in bits. |
k |
the number of required iterations to find GCD. |
q |
the sequence of partial quotients. |
g |
the value of greatest common divisor. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
result=GCD.big(14532710900972355716,4463510164971546043,64) print(result)
result=GCD.big(14532710900972355716,4463510164971546043,64) print(result)
Finds the greatest common divisor (GCD) of two integers using the Euclidean algorithm. In addition to the value of GCD, it generates the number of required iterations to find GCD and the sequence of partial quotients.
GCD.q(x, y)
GCD.q(x, y)
x |
the first integer greater than zero. |
y |
the second integer greater than zero. |
k |
the number of required iterations to find GCD. |
q |
the sequence of partial quotients. |
g |
the value of greatest common divisor. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
result=GCD.q(4535,2451) print(result) result=GCD.q(35,2) print(result)
result=GCD.q(4535,2451) print(result) result=GCD.q(35,2) print(result)
Performs Greatest Common Divisor (GCD) test of Marsaglia and Tsang (2002) to evaluate the randomness of an RNG. Randomness tests are conducted over two outputs of greatest common divisor operation, namely the number of required iterations and the value of greatest common divisor. The Kolmogorov-Smirnov, Anderson-Darling, Jarque-Bera, and Chi-Square tests are applied as goodness-of-fit tests when the test is conducted over the number of required iterations. The Kolmogorov-Smirnov and Chi-Square tests are applied as goodness-of-fit tests when the test is conducted over the value of greatest common divisor.
GCD.test(x, B = 32, KS = TRUE, CSQ = TRUE, AD = TRUE, JB = TRUE, test.k = TRUE, test.g = TRUE, mu, sd, alpha = 0.05)
GCD.test(x, B = 32, KS = TRUE, CSQ = TRUE, AD = TRUE, JB = TRUE, test.k = TRUE, test.g = TRUE, mu, sd, alpha = 0.05)
x |
an |
B |
the length of words (B-bit). |
KS |
if |
CSQ |
if |
AD |
if |
JB |
if |
test.k |
if |
test.g |
if |
mu |
the mean of theoretical normal distribution that the number of required iterations follows. |
sd |
the standard deviation of theoretical normal distribution that the number of required iterations follows. |
alpha |
a predetermined value of significance level with the default value of 0.05. |
Total number of integers to be tested is divided into two sets and entered as x
. The GCD operation is applied to each row of x
.
The number of required iterations follows a normal distribution with parameters mu
and sd
. Values of mu
and sd
are obtained by Monte Carlo simulation and given by Marsaglia and Tsang (2002) for 32-bit setting. We obtained values of mu
and sd
for other bit settings as mu=4.2503, sd=1.650673
for 8-bits, mu=8.8772, sd=2.38282
for 16-bits, ...for 24-bits,...
sig.value.k |
a |
sig.value.g |
a |
KS.result.k |
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted over the number of required iterations. |
CSQ.result.k |
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted over the number of required iterations. |
JB.result.k |
returns 0 if H0 is rejected and 1 otherwise in Jarque-Bera goodness-of-fit test conducted over the number of required iterations. |
AD.result.k |
returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test conducted over the number of required iterations. |
KS.result.g |
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted over the value of greatest common divisor. |
CSQ.result.g |
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted over the value of greatest common divisor. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3).
See the function GCD
that provides detailed results for the greatest common divisor operation.
RNGkind(kind = "L'Ecuyer-CMRG") B=16 # Bit length is 16. k=250 # Generate 250 integers. x=array(0,dim=c(k,2)) x[,1]=round(runif(k,0,(2^B-1))) x[,2]=round(runif(k,0,(2^B-1))) mu=8.8772 sd=2.38282 alpha = 0.05 test=GCD.test(x,B=B,KS=TRUE,CSQ=TRUE,AD=TRUE,JB=TRUE, test.k=TRUE,test.g=TRUE,mu=mu,sd=sd,alpha=alpha) print(test)
RNGkind(kind = "L'Ecuyer-CMRG") B=16 # Bit length is 16. k=250 # Generate 250 integers. x=array(0,dim=c(k,2)) x[,1]=round(runif(k,0,(2^B-1))) x[,2]=round(runif(k,0,(2^B-1))) mu=8.8772 sd=2.38282 alpha = 0.05 test=GCD.test(x,B=B,KS=TRUE,CSQ=TRUE,AD=TRUE,JB=TRUE, test.k=TRUE,test.g=TRUE,mu=mu,sd=sd,alpha=alpha) print(test)
Prints a summary of test results.
## S3 method for class 'CryptRndTest' print(x,...)
## S3 method for class 'CryptRndTest' print(x,...)
x |
an object including information to be printed. |
... |
other arguments. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Performs random walk tests of Doganaksoy et al. (2006) to evaluate the randomness of an RNG. It runs Random Walk Excursion, Random Walk Expansion, and Random Walk Height tests.
random.walk.tests(x, B = 64, Excursion = TRUE, Expansion = TRUE, Height = TRUE, alpha = 0.05)
random.walk.tests(x, B = 64, Excursion = TRUE, Expansion = TRUE, Height = TRUE, alpha = 0.05)
x |
a matrix that includes random data in base-2 format. See details for further information. |
B |
the length of words (B-bit). See Details section. |
Excursion |
if |
Expansion |
if |
Height |
if |
alpha |
a predetermined value of significance level with the default value of 0.05. |
Argument x
should be entered as a matrix of bits of dimension x
, where
is the number of words (integers) generated by the RNG of interest.
If Excursion
is TRUE, B takes the values 16, 32, 64, 128, and 256. If Height
is TRUE, B takes 64, 128, 256, 512, and 1024. If Expansion
is TRUE, B takes 32, 64, and 128. Because theoretical cumulative distribution functions for the other word lengths, random.walk.tests()
performs tests under given bit settings. If one of the tests is not applied, all the results related with that test in output are set to -1.
AD.statistic.Excursion |
value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
KS.statistic.Excursion |
value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
CS.statistic.Excursion |
value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
AD.pvalue.Excursion |
p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
KS.pvalue.Excursion |
p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
CS.pvalue.Excursion |
p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
AD.result.Excursion |
returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
KS.result.Excursion |
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
CS.result.Excursion |
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted after application of Random Walk Excursion procedure. |
AD.statistic.Expansion |
value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
KS.statistic.Expansion |
value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
CS.statistic.Expansion |
value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
AD.pvalue.Expansion |
p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
KS.pvalue.Expansion |
p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
CS.pvalue.Expansion |
p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
AD.result.Expansion |
returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
KS.result.Expansion |
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
CS.result.Expansion |
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted after application of Random Walk Expansion procedure. |
AD.statistic.Height |
value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Height procedure. |
KS.statistic.Height |
value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Height procedure. |
CS.statistic.Height |
value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Height procedure. |
AD.pvalue.Height |
p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Height procedure. |
KS.pvalue.Height |
p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Height procedure. |
CS.pvalue.Height |
p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Height procedure. |
AD.result.Height |
returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test conducted after application of Random Walk Height procedure. |
KS.result.Height |
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Height procedure. |
CS.result.Height |
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted after application of Random Walk Height procedure. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Doganaksoy, A., Calik, C., Sulak, F., Turan, M.S., New randomness tests using random walk, In: National Cryptology Symposium II, (2006), Ankara, Turkey.
RNGkind(kind = "Super-Duper") B=64 # Bit length is 64. k=500 # Generate 500 integers. dat=round(runif(k,0,(2^B-1))) x=sfsmisc::digitsBase(dat, base= 2, B) #Convert to base 2 alpha = 0.05 test=random.walk.tests(x, B, Excursion = TRUE, Expansion = TRUE, Height = TRUE, alpha) print(test)
RNGkind(kind = "Super-Duper") B=64 # Bit length is 64. k=500 # Generate 500 integers. dat=round(runif(k,0,(2^B-1))) x=sfsmisc::digitsBase(dat, base= 2, B) #Convert to base 2 alpha = 0.05 test=random.walk.tests(x, B, Excursion = TRUE, Expansion = TRUE, Height = TRUE, alpha) print(test)
Asymptotically computes natural logarithm of Stirling numbers of the second kind for large values of inputs by the approach of Bleick and Wang (1954) and Temme (1993). For small or moderate values of inputs, this function is not as precise as available functions.
Strlng2(n, k, log = TRUE)
Strlng2(n, k, log = TRUE)
n |
positive integer greater than zero. |
k |
positive integer between 1 and |
log |
if |
Due to the overflows in the calculation of large factorials, an asymptotic calculation of the Stirling numbers of the second kind is required. This function makes use of Lambert W function to calculate the Stirling numbers of the second kind with large values of n
and k
.
Stirling.num |
the corresponding Stirling number of the second kind to the pair |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Bleick, W.W., Wang, P.C.C., Asymptotics of Stirling Numbers of the Second Kind. Proceedings of the American Mathematical Society (1974), 42(2), 575–580.
Temme, N.M., Asymptotic estimates of Stirling numbers. Studies in Applied Mathematics (1993), 89, 233–243.
See also Stirling2
function from the package copula.
# When n = 10 and k = 4, exact value is 34105 gmp::Stirling2(10,4) Strlng2(10,4,log=FALSE) # ---- Moderate values of n and k ---- # When n = 30 and k = 20, exact value is 581535955088511150 log(581535955088511150)-log(gmp::Stirling2(30,20)) log(581535955088511150)-Strlng2(30,20,log=TRUE) # ---- Large values of n and k ---- gmp::Stirling2(50,10) Strlng2(50,10,log=FALSE)
# When n = 10 and k = 4, exact value is 34105 gmp::Stirling2(10,4) Strlng2(10,4,log=FALSE) # ---- Moderate values of n and k ---- # When n = 30 and k = 20, exact value is 581535955088511150 log(581535955088511150)-log(gmp::Stirling2(30,20)) log(581535955088511150)-Strlng2(30,20,log=TRUE) # ---- Large values of n and k ---- gmp::Stirling2(50,10) Strlng2(50,10,log=FALSE)
Approximately computes cumulative distribution function of the test statistic of the Topological Binary Test of Alcover et al. (2013) and finds the required critical value for the test.
TBT.criticalValue(m, k, alpha = 0.01, cdf = FALSE, exact = TRUE)
TBT.criticalValue(m, k, alpha = 0.01, cdf = FALSE, exact = TRUE)
m |
the length of words (B-bit) in Topological Binary Test. |
k |
the number of words (integers) generated by the RNG of interest that will be tested. |
alpha |
a predetermined value of type-I error with the default value of 0.05. |
cdf |
if |
exact |
if |
The function TBT.criticalValue
lists the cumulative probabilities greater than zero if cdf
is set to TRUE
.
A correction factor is applied to improve accuracy of the the function Strlng2
in the computation of probabilities. Accuracy of the computations decreases with increasing value of m
.
prob |
a vector containing the cumulative probabilities corresponding to the values in |
value |
a vector containing the values of the test statistic. |
critical.value |
critical value of the test statistic corresponding to |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Alcover, P.M., Guillamon, A., Ruiz, M.C., A new randomness test for bit sequences. Informatica (2013), 24(3), 339–356.
# Critical values for the Topological Binary Test at 0.01 and 0.05 levels of significance. TBT.criticalValue(m=8, k=256, alpha=0.01, cdf=FALSE, exact=FALSE) TBT.criticalValue(m=8, k=256, alpha=0.05, cdf=FALSE, exact=FALSE)
# Critical values for the Topological Binary Test at 0.01 and 0.05 levels of significance. TBT.criticalValue(m=8, k=256, alpha=0.01, cdf=FALSE, exact=FALSE) TBT.criticalValue(m=8, k=256, alpha=0.05, cdf=FALSE, exact=FALSE)
Converts large integers form base 2 to base 10 using mpfr numbers by Pmpfr package.
toBaseTen(x, m = 128, prec = 256, toFile = FALSE, file)
toBaseTen(x, m = 128, prec = 256, toFile = FALSE, file)
x |
an m-by-k binary matrix including the data in base 2. |
m |
desired bit length in the output. |
prec |
precision of the calculations. |
toFile |
if |
file |
the path of the file to which the output is written. |
dat |
an m-by-k matrix that contains the input data in base 10 format. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Converts large integers form base 10 to base 2 using mpfr numbers by Pmpfr package.
toBaseTwo(x, m = 128, prec = 512, num.CPU = 4)
toBaseTwo(x, m = 128, prec = 512, num.CPU = 4)
x |
an mpfr vector including the data in base 10. |
m |
desired bit length in the output. |
prec |
precision of the calculations. |
num.CPU |
the number of CPUs that will be used in parallel computing. |
The function toBaseTwo utilizes the package parallel to make calculation utilizing parallel computing.
r.bit |
a list of mpfr numbers that contains the input data in base 2 format. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Performs Topological Binary Test of Alcover et al. (2013) to evaluate the randomness of an RNG. No additional goodness-of-fit test is applied after calculation of test statistic of Topological Binary Test.
topological.binary(x, B, alpha = 0.05, critical.value)
topological.binary(x, B, alpha = 0.05, critical.value)
x |
a matrix that includes random data in base-2 format. See details for further information. |
B |
the length of words (B-bit). |
alpha |
a predetermined value of significance level with the default value of 0.05. |
critical.value |
a value used to decide whether to reject the null hypothesis at the significance level of |
The argument x
should be entered as a matrix of bits of dimension x
, where
is the number of words (integers) generated by the RNG of interest.
The argument critical.value
should be calculated regarding the value of B
. For , values of
critical.value
are tabulated by Alcover et al. (2013) and calculation procedure of critical.value
for the values greater than 16 is described therein. The tabulated values can be used if the number of words () is equal to
. Otherwise, it should be calculated over the given cumulative distribution function by Alcover et al. (2013). For example, if
, then
critical.value
and if
, then
critical.value
.
Topological binary test is itself constitutes a goodness-of-fit test based on the number of different B-bit patterns among the non-overlapping B-bit blocks composed of the input sequence of bits.
statistic |
calculated value of the test statistic. |
result.TBT |
returns 0 if H0 is rejected and 1 otherwise. |
Haydar Demirhan
Maintainer: Haydar Demirhan <[email protected]>
Alcover, P.M., Guillamon, A., Ruiz, M.C., A new randomness test for bit sequences. Informatica (2013), 24(3), 339–356.
RNGkind(kind = "Super-Duper") B=16 # Bit length is 16. k=5000 # Generate 5000 integers. dat=round(runif(k,0,(2^B-1))) x=sfsmisc::digitsBase(dat, base= 2, B) #Convert to base 2 alpha = 0.05 critical.value=9245 #Obtained for B = 16 test=topological.binary(x, B, alpha, critical.value) print(test)
RNGkind(kind = "Super-Duper") B=16 # Bit length is 16. k=5000 # Generate 5000 integers. dat=round(runif(k,0,(2^B-1))) x=sfsmisc::digitsBase(dat, base= 2, B) #Convert to base 2 alpha = 0.05 critical.value=9245 #Obtained for B = 16 test=topological.binary(x, B, alpha, critical.value) print(test)