diff --git a/DESCRIPTION b/DESCRIPTION index 938e3d8..3866b0a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,15 @@ Package: CryptRndTest Type: Package Title: Statistical Tests for Cryptographic Randomness -Version: 1.1.5 -Date: 2015-09-01 +Version: 1.2.1 +Date: 2015-12-24 Author: Haydar Demirhan Maintainer: Haydar Demirhan -Description: Performs cryptographic randomness tests on a sequence of random integers or bits. Most of the included tests 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. +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. 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. Depends: MissMech, kSamples, sfsmisc, Rmpfr, parallel Imports: LambertW, gmp, tseries, methods License: GPL-3 NeedsCompilation: no -Packaged: 2015-09-01 09:14:41 UTC; 114F249_Nihan +Packaged: 2016-01-04 14:02:49 UTC; Stat Repository: CRAN -Date/Publication: 2015-09-01 17:39:23 +Date/Publication: 2016-01-04 15:28:45 diff --git a/MD5 b/MD5 index a14f9d4..e0e0df2 100644 --- a/MD5 +++ b/MD5 @@ -1,37 +1,51 @@ -5c65d88be15ddafb4e9ae2af173cfd91 *DESCRIPTION -b6c7f28a9724b837801d87eb0a3fb5c0 *NAMESPACE -6225a0183f2419adc72ff8f788ff2835 *R/CryptRndTest-internal.R +89ff16fe4b2d24a05939a1041d6e21b6 *DESCRIPTION +0963ce0eccb698dace2a13f4c2374f5f *NAMESPACE a932de32fc9531dc82b578764ed2a871 *R/GCD.R 1b7c36ec62dbbabfecd8a2f51a23ac7b *R/GCD.big.R 991a5fdabd63162144bf066ae0239952 *R/GCD.q.R -f801c358709129a4bbd7d2d833f9c93a *R/GCD.test.R +3ae5da7ed136aac85a8518f33f23a372 *R/GCD.test.R +a9c19cd33bb198ae37669ed3d8a44bbb *R/GCD.test.default.R +39ca022cbc9abbd5e6b125cb5f31e925 *R/GCD.test.main.R 1d0b330f6fbf6df7cede853d1654702d *R/KSADCHRY.R 4b1f39183e0f932064e57c0e776e5489 *R/KSADdga.R 674b384db89264e1cd498000c1bf4cac *R/Random.walk.D.R -4744acec9b67818f76ffa56b72d98d67 *R/Random.walk.G.R +49b1ffdad04d96463b6e7fbdd2e509ae *R/Random.walk.G.R 44c5acbbf64b2ce7a6185ea1cfde1b75 *R/Random.walk.Y.R c0e1d7d5b2e99f12381baff7bcc83557 *R/Strlng2.R b146cdcc7754738270f83214953c81b2 *R/TBT.criticalValue.R -9a4f919dd36740d9c1b0bc1987435b94 *R/adaptive.chi.square.R -f3dd9aec704b86a34271350017b1863e *R/birthday.spacings.R -8a60af1f95810f0490df2a3d46ba78d6 *R/book.stack.R -a9608f0bbc95ddca7bd716f63e3d6704 *R/dogumGunuAraliklari.R -4ea3016f4cab1d61fb7ee837b9369f6c *R/random.walk.tests.R +27ab4c3a917cd0bae30f7f6f7a0e19b8 *R/adaptive.chi.square.R +4c6d3f2a968d8da73e15ee1f39816452 *R/adaptive.chi.square.default.R +73d0184dd76ae4ef9e6dff29ab5f2497 *R/adaptive.chi.square.main.R +f26b10871afe4a43a5bbfe9ae287bb94 *R/birthday.spacings.R +77cfb3f086ee6c74da489d667d030f12 *R/birthday.spacings.default.R +6b07f97a62a977bcf86fdab38e2b8e1d *R/birthday.spacings.main.R +7b18a6290a22288cfe9694d65744db86 *R/book.stack.R +5597e999245639ac80823c6cacfcecdc *R/book.stack.default.R +bfbc1d56f97ceb05808651095f9b8874 *R/book.stack.main.R +5f4bd284f4e8ca31298533ea5cfb95cb *R/check.R +b1fbe8fbf7a8d1430168769b8abe4df2 *R/dogumGunuAraliklari.R +544138ab7e3960a5b8081b51d6c264ee *R/print.CryptRndTest.R +51438bc546b86700112474a1f871f36b *R/random.walk.tests.R +a20eb094a838f5e93b4c295bb6501060 *R/random.walk.tests.default.R +d4d7cf67230cf1eeaf304922e40e53d4 *R/random.walk.tests.main.R 0c5b628c60a42b21e695e92bda4467f5 *R/toBaseTen.R 2bb031d6101c523751cd573730231ff5 *R/toBaseTwo.R -330c965d7d7ccfab85d791687bc74c98 *R/topological.binary.R -c378b15518874d3bb760fe9b3e56168c *man/CryptRndTest-internal.Rd -3475becdda643b5cb2a7954aa27e756b *man/CryptRndTest-package.Rd +a32856d16ca0bc9115ff315de240a8b0 *R/topological.binary.R +e2c3869bc7ac9778cc91f540ca626a02 *R/topological.binary.default.R +eeff0d1eb017d5816107be7adb6fa1e6 *R/topological.binary.main.R +9b78c028ccdde86a855a1044e308045d *man/CryptRndTest-internal.Rd +8417e8482197942e52749537d0abb273 *man/CryptRndTest-package.Rd 46426b0a1c9aa431340b333f7a425b58 *man/GCD.Rd 1dd353fe833e9128ba46aa48971c781c *man/GCD.big.Rd 1349f0f5ed2ad37201f883d75b3c06d0 *man/GCD.q.Rd -7d20cca810e0bf0301c902aef53c193b *man/GCD.test.Rd +475c50f123690dcdfe555ad3a94b8c31 *man/GCD.test.Rd 2bcf2f6e1c7162ba0d259aad3a323485 *man/Strlng2.Rd 31ed38336ca337fbe27ed32e5ea318c5 *man/TBT.criticalValue.Rd -19f1c9b686b930835094f349eba8bd4a *man/adaptive.chi.square.Rd -55ba059b1f66cb2b5015edf64666a991 *man/birthday.spacings.Rd -09d7621ab337045ec08f3924573c9b24 *man/book.stack.Rd -af675753f6b7b09c91db40e5975e3c28 *man/random.walk.tests.Rd +50dd11664dbc804c6ed8ccdce4aa7a2a *man/adaptive.chi.square.Rd +ed00fe05150d9001fcbb4f69ff04419b *man/birthday.spacings.Rd +0babf1004e341378ce5e6b3746d2201f *man/book.stack.Rd +060765a6f1e7ffcf9dd75cdd158f2f06 *man/print.CryptRndTest.Rd +000f0562fdf36ef9dd71a86fda1cabd3 *man/random.walk.tests.Rd 0f3a9dc2818890821b8f6c0ff1a1062d *man/toBaseTen.Rd cdd3c1619aeec3a159da599e83cc4008 *man/toBaseTwo.Rd -84fb73bbe16f992208e5da0f71a07917 *man/topological.binary.Rd +f8273920ea3772dd41a149405b8315e7 *man/topological.binary.Rd diff --git a/NAMESPACE b/NAMESPACE index 970a24c..0738db7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,17 +1,57 @@ -exportPattern("^[[:alpha:]]+") +exportPattern("^[[:alpha:]]+") + importFrom(sfsmisc,digitsBase) + importFrom(tseries,jarque.bera.test) -importFrom(kSamples,ad.test) + +importFrom(kSamples,ad.test) + importFrom(MissMech,AndersonDarling) + importFrom(LambertW,W) + importFrom(gmp,Stirling2) -importFrom(Rmpfr,mpfr) + +importFrom(Rmpfr,mpfr) + importFrom(Rmpfr,mpfrArray) + importFrom(parallel,makePSOCKcluster) + importFrom(parallel,setDefaultCluster) importFrom(parallel,clusterExport) + importFrom(parallel,parLapply) + importFrom(parallel,stopCluster) + importFrom("stats", "chisq.test", "dpois", "ks.test", "pchisq","rnorm", "runif") + importFrom("methods", "new") + importFrom("utils", "write.table") + +S3method(adaptive.chi.square,default) + +S3method(birthday.spacings,default) + +S3method(book.stack,default) + +S3method(GCD.test,default) + +S3method(random.walk.tests,default) +S3method(topological.binary,default) + + +S3method(adaptive.chi.square,main) + +S3method(birthday.spacings,main) + +S3method(book.stack,main) + +S3method(GCD.test,main) + +S3method(random.walk.tests,main) +S3method(topological.binary,main) + +S3method(print,CryptRndTest) diff --git a/R/CryptRndTest-internal.R b/R/CryptRndTest-internal.R deleted file mode 100644 index 6046913..0000000 --- a/R/CryptRndTest-internal.R +++ /dev/null @@ -1,2 +0,0 @@ -.Random.seed <- -c(402L, -162821854L, 1575042963L) diff --git a/R/GCD.test.R b/R/GCD.test.R index a358c77..8f5b023 100644 --- a/R/GCD.test.R +++ b/R/GCD.test.R @@ -1,144 +1 @@ -GCD.test=function(x,B=32,KS=TRUE,CSQ=TRUE,AD=TRUE,JB=TRUE,test.k=TRUE,test.g=TRUE,mu,sd,alpha=0.05){ - if (sum(x==0)>0){ - stop("Input includes invalid value: 0.") - } - num=as.matrix(x) - N=nrow(num) - y=0 - z=0 - y2=0 - oklit=0 - sig.value.k=array(NA,dim=4) - sig.value.g=array(NA,dim=2) - - if (B<=64){ - for (i in 1:N){ - oklit=GCD.q(num[i,1],num[i,2]) - y[i]=oklit$k - if (oklit$g<3) { - y2[i]=3 - }else if (oklit$g>35){ - y2[i]=35 - }else{ - y2[i]=as.numeric(oklit$g) - } - } - }else { - for (i in 1:N){ - y[i]=GCD(num[i,1],num[i,2])$k #uses recursive algo - #tests for g will not be applied for 128 bit numbers - } - - } - if (test.k==TRUE){ - teorik.Normal=round(rnorm(N,mu,sd)) - if (KS==TRUE){ - sig.value.k[1]=ks.test(y,teorik.Normal,alternative = "two.sided")$p.value - if (sig.value.k[1]=10000){ - testAD=kSamples::ad.test(list(y[1:5000],teorik.Normal[1:5000]),method="asymptotic",dist=FALSE,Nsim=500) - }else{ - testAD=kSamples::ad.test(list(y[1:(N/2)],teorik.Normal[1:(N/2)]),method="asymptotic",dist=FALSE,Nsim=500) - } - sig.value.k[4]=testAD$ad[1,3] - if (sig.value.k[4]35){ - teorik[bsl:N]=35 - teo[i]=N+1 - }else if(i<3){ - teorik[bsl:(bsl+teo[i]-1)]=3 - bsl=bsl+teo[i] - }else{ - teorik[bsl:(bsl+teo[i]-1)]=i - bsl=bsl+teo[i] - } - } - } - - if (KS==TRUE){ - sig.value.g[1]=ks.test(y2,teorik,alternative = "two.sided")$p.value - if (sig.value.g[1]0){ + stop("Input includes invalid value: 0.") + } + num=as.matrix(x) + N=nrow(num) + y=0 + z=0 + y2=0 + oklit=0 + sig.value.k=array(NA,dim=4) + sig.value.g=array(NA,dim=2) + + if (B<=64){ + for (i in 1:N){ + oklit=GCD.q(num[i,1],num[i,2]) + y[i]=oklit$k + if (oklit$g<3) { + y2[i]=3 + }else if (oklit$g>35){ + y2[i]=35 + }else{ + y2[i]=as.numeric(oklit$g) + } + } + }else { + for (i in 1:N){ + y[i]=GCD(num[i,1],num[i,2])$k #uses recursive algo + #tests for g will not be applied for 128 bit numbers + } + + } + if (test.k==TRUE){ + teorik.Normal=round(rnorm(N,mu,sd)) + if (KS==TRUE){ + sig.value.k[1]=ks.test(y,teorik.Normal,alternative = "two.sided")$p.value + if (sig.value.k[1]=10000){ + testAD=kSamples::ad.test(list(y[1:5000],teorik.Normal[1:5000]),method="asymptotic",dist=FALSE,Nsim=500) + }else{ + testAD=kSamples::ad.test(list(y[1:(N/2)],teorik.Normal[1:(N/2)]),method="asymptotic",dist=FALSE,Nsim=500) + } + sig.value.k[4]=testAD$ad[1,3] + if (sig.value.k[4]35){ + teorik[bsl:N]=35 + teo[i]=N+1 + }else if(i<3){ + teorik[bsl:(bsl+teo[i]-1)]=3 + bsl=bsl+teo[i] + }else{ + teorik[bsl:(bsl+teo[i]-1)]=i + bsl=bsl+teo[i] + } + } + } + + if (KS==TRUE){ + sig.value.g[1]=ks.test(y2,teorik,alternative = "two.sided")$p.value + if (sig.value.g[1]64){ - ss=new('mpfr',unlist(ss)) - } - for (i in 1:length(ss)){ - freq[i]=sum((ss[i]==egitimVeri)==TRUE) - - freq2[i]=sum((ss[i]==testVeri)==TRUE) - } - AA=0 - AA2=0 - for (i in 1:S){ - AA[i]=sum(freq==(i-1)) - AA2[i]=sum(freq2==(i-1)) - } - - statistic=sum((AA2[which(AA2>0)]-AA[which(AA>0)])^2/AA[which(AA>0)]) - pDegeri=1-pchisq(statistic,(S-1)) - - if (pDegeri64){ + ss=new('mpfr',unlist(ss)) + } + for (i in 1:length(ss)){ + freq[i]=sum((ss[i]==egitimVeri)==TRUE) + + freq2[i]=sum((ss[i]==testVeri)==TRUE) + } + AA=0 + AA2=0 + for (i in 1:S){ + AA[i]=sum(freq==(i-1)) + AA2[i]=sum(freq2==(i-1)) + } + + statistic=sum((AA2[which(AA2>0)]-AA[which(AA>0)])^2/AA[which(AA>0)]) + pDegeri=1-pchisq(statistic,(S-1)) + + if (pDegeri=1)){ + stop("The significance level alpha must be entered between 0 and 1!") + } + if (test==1){ + if ((prop<=0) | (prop>=1)){ + stop("The proportion of test and training data sets in adaptive chi-square test must be entered between 0 and 1!") + } + if ((abs(S - round(S)) < (.Machine$double.eps^0.5))==FALSE){ + stop("An integer value should be entered for the number of sub-alphabets in adaptive chi-square test!") + } + } + if (test!=2){ + if (is.null(bit)==FALSE){ + if (is.logical(bit)==FALSE){ + stop("A logical value must be entered for bit!") + } + if ((bit==TRUE) & (all(x %in% 0:1)==FALSE)){ #Are all elements of x either 0 or 1? + stop("Input sequence must contain binary entries when bit is set to TRUE!") + } + if ((bit==FALSE) & (is.numeric(x)==FALSE)){ #Are all elements of x numeric? + stop("Input sequence must contain numeric entries when bit is set to FALSE!") + } + } + if (is.numeric(B)==FALSE){ + stop("Bit length must be a numeric entry!") + } + if ((abs(B - round(B)) < (.Machine$double.eps^0.5))==FALSE){ #is B a wholenumber + stop("Bit length must be an integer!") + } + + } + if (test==2){ + if ((abs(num.class - round(num.class)) < (.Machine$double.eps^0.5))==FALSE){ + stop("An integer value should be entered for the number of classes in birthday spacings test!") + } + if ((abs(m - round(m)) < (.Machine$double.eps^0.5))==FALSE){ + stop("An integer value should be entered for the number of birthdays in birthday spacings test!") + } + if (lambda<0){ + stop("A positive value should be entered for mean rate of theoretical Poisson distribution in birthday spacings test!") + } + } + if (test==3){ + if ((abs(k - round(k)) < (.Machine$double.eps^0.5))==FALSE){ + stop("An integer value should be entered for k in book stack test!") + } + } + if (test==4){ + if ((is.logical(KS)==FALSE)|(is.logical(CSQ)==FALSE)|(is.logical(AD)==FALSE)|(is.logical(JB)==FALSE)| + (is.logical(test.k)==FALSE)|(is.logical(test.g)==FALSE)){ + stop("At least one of the logical arguments of GCD test is entered unlogical!") + } + if (sd<0){ + stop("A positive value should be entered for standard deviation of theoretical normal distribution in GCD test!") + } + } + if (test==5){ + if ((is.logical(Excursion)==FALSE)|(is.logical(Expansion)==FALSE)|(is.logical(Height)==FALSE)){ + stop("At least one of the logical arguments of random walk tests is entered unlogical!") + } + } + if (test==6){ + if (critical.value<=0){ + stop("Critical value of topological binary test must be positive!") + } + } + + } \ No newline at end of file diff --git a/R/dogumGunuAraliklari.R b/R/dogumGunuAraliklari.R index 37e1ffb..8d03ca2 100644 --- a/R/dogumGunuAraliklari.R +++ b/R/dogumGunuAraliklari.R @@ -2,7 +2,7 @@ dogumGunuAraliklari <-function(e,m){ ee=0 n=length(e) dat=matrix(e[1:(m*floor(n/m))],nrow=floor(n/m),byrow=TRUE) - dat.sorted=unlist(t(apply(dat,1,sort)) ) + dat.sorted=unlist(t(apply(dat,1,sort)) ) dat.diff=t(diff(t(dat.sorted))) dat.num.duplicated=apply(dat.diff,1,function(dat.diff){sum(duplicated(dat.diff)==TRUE)}) diff --git a/R/print.CryptRndTest.R b/R/print.CryptRndTest.R new file mode 100644 index 0000000..5d33460 --- /dev/null +++ b/R/print.CryptRndTest.R @@ -0,0 +1,327 @@ +print.CryptRndTest <- function(x,...){ + + if (x$name=="Achi"){ + cat("\n"," ","Test results for Adaptive Chi-Square test") + cat("\n"," ","-----------------------------------------") + cat("\n"," ","Value :",paste(round(x$statistic,digits=3))) + if (round(x$p.value,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$p.value,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$p.value,digits=3)) + } + if (x$result.acsq==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$result.acsq==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------") + } else if (x$name=="BDS"){ + cat("\n"," ","Test results for Birthday Spacings test ") + cat("\n"," ","----------------------------------------------") + cat("\n"," ","with Anderson-Darling goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$AD.statistic,digits=3))) + if (round(x$AD.pvalue,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$AD.pvalue,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$AD.pvalue,digits=3)) + } + if (x$AD.result==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$AD.result==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","----------------------------------------------") + cat("\n"," ","with Kolmogorov-Smirnov goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$KS.statistic,digits=3))) + if (round(x$KS.pvalue,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$KS.pvalue,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$KS.pvalue,digits=3)) + } + if (x$KS.result==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$KS.result==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","----------------------------------------------") + cat("\n"," ","with Chi-Square goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$CS.statistic,digits=3))) + if (round(x$CS.pvalue,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$CS.pvalue,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$CS.pvalue,digits=3)) + } + if (x$CS.result==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$CS.result==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","----------------------------------------------") + }else if (x$name=="BS"){ + cat("\n"," ","Test results for Book Stack test") + cat("\n"," ","-----------------------------------------") + cat("\n"," ","Value :",paste(round(x$statistic,digits=3))) + if (round(x$p.value,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$p.value,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$p.value,digits=3)) + } + if (x$BS.result==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$BS.result==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------") + }else if (x$name=="GCD"){ + cat("\n"," ","Test results for Greatest Common Divisor test") + cat("\n"," ","-----------------------------------------------") + if (x$test.k==TRUE){ + cat("\n"," ","Results for the tests over k:") + cat("\n"," ","with Anderson-Darling goodness of fit test:") + if (round(x$sig.value.k[4],digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$sig.value.k[4],digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$sig.value.k[4],digits=3)) + } + if (x$AD.result.k==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$AD.result.k==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Kolmogorov-Smirnov goodness of fit test:") + if (round(x$sig.value.k[1],digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$sig.value.k[1],digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$sig.value.k[1],digits=3)) + } + if (x$KS.result.k==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$KS.result.k==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Chi-Square goodness of fit test:") + if (round(x$sig.value.k[2],digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$sig.value.k[2],digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$sig.value.k[2],digits=3)) + } + if (x$CSQ.result.k==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$CSQ.result.k==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Jarque-Bera goodness of fit test:") + if (round(x$sig.value.k[3],digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$sig.value.k[3],digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$sig.value.k[3],digits=3)) + } + if (x$JB.result.k==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$JB.result.k==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------------") + } + if (x$test.g==TRUE){ + cat("\n"," ","Results for the tests over k:") + cat("\n"," ","with Kolmogorov-Smirnov goodness of fit test:") + if (round(x$sig.value.g[1],digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$sig.value.g[1],digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$sig.value.g[1],digits=3)) + } + if (x$KS.result.g==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$KS.result.g==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Chi-Square goodness of fit test:") + if (round(x$sig.value.g[2],digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$sig.value.g[2],digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$sig.value.g[2],digits=3)) + } + if (x$CSQ.result.g==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$CSQ.result.g==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------------") + } + }else if (x$name=="RW"){ + cat("\n"," ","Test results for Random Walk tests") + cat("\n"," ","-----------------------------------------------") + if (x$Exc==TRUE){ + cat("\n"," ","Results for Excursion tests:") + cat("\n"," ","with Anderson-Darling goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$AD.statistic.Excursion,digits=3))) + if (round(x$AD.pvalue.Excursion,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$AD.pvalue.Excursion,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$AD.pvalue.Excursion,digits=3)) + } + if (x$AD.result.Excursion==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$AD.result.Excursion==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Kolmogorov-Smirnov goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$KS.statistic.Excursion,digits=3))) + if (round(x$KS.pvalue.Excursion,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$KS.pvalue.Excursion,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$KS.pvalue.Excursion,digits=3)) + } + if (x$KS.result.Excursion==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$KS.result.Excursion==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Chi-Square goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$CS.statistic.Excursion,digits=3))) + if (round(x$CS.pvalue.Excursion,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$CS.pvalue.Excursion,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$CS.pvalue.Excursion,digits=3)) + } + if (x$CS.result.Excursion==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$CS.result.Excursion==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------------") + } + if (x$Exp==TRUE){ + cat("\n"," ","Results for Expansion tests:") + cat("\n"," ","with Anderson-Darling goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$AD.statistic.Expansion,digits=3))) + if (round(x$AD.pvalue.Expansion,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$AD.pvalue.Expansion,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$AD.pvalue.Expansion,digits=3)) + } + if (x$AD.result.Expansion==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$AD.result.Expansion==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Kolmogorov-Smirnov goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$KS.statistic.Expansion,digits=3))) + if (round(x$KS.pvalue.Expansion,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$KS.pvalue.Expansion,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$KS.pvalue.Expansion,digits=3)) + } + if (x$KS.result.Expansion==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$KS.result.Expansion==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Chi-Square goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$CS.statistic.Expansion,digits=3))) + if (round(x$CS.pvalue.Expansion,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$CS.pvalue.Expansion,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$CS.pvalue.Expansion,digits=3)) + } + if (x$CS.result.Expansion==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$CS.result.Expansion==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------------") + } + if (x$Hei==TRUE){ + cat("\n"," ","Results for Height tests:") + cat("\n"," ","with Anderson-Darling goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$AD.statistic.Height,digits=3))) + if (round(x$AD.pvalue.Height,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$AD.pvalue.Height,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$AD.pvalue.Height,digits=3)) + } + if (x$AD.result.Height==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$AD.result.Height==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Kolmogorov-Smirnov goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$KS.statistic.Height,digits=3))) + if (round(x$KS.pvalue.Height,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$KS.pvalue.Height,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$KS.pvalue.Height,digits=3)) + } + if (x$KS.result.Height==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$KS.result.Height==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","with Chi-Square goodness of fit test:") + cat("\n"," ","Value :",paste(round(x$CS.statistic.Height,digits=3))) + if (round(x$CS.pvalue.Height,digits=3)==1){ + cat("\n"," ","p-Value:",">0.999") + }else if (round(x$CS.pvalue.Height,digits=3)==0){ + cat("\n"," ","p-Value:","<0.001") + }else{ + cat("\n"," ","p-Value:",round(x$CS.pvalue.Height,digits=3)) + } + if (x$CS.result.Height==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$CS.result.Height==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------------") + } + }else if (x$name=="TBT"){ + cat("\n"," ","Test results for Topological Binary test") + cat("\n"," ","-----------------------------------------") + cat("\n"," ","Value :",paste(round(x$statistic,digits=3))) + if (x$result.TBT==0){ + cat("\n"," ","Result : Reject H0") + }else if (x$result.TBT==1){ + cat("\n"," ","Result : Not reject H0") + } + cat("\n"," ","-----------------------------------------") + } + + } \ No newline at end of file diff --git a/R/random.walk.tests.R b/R/random.walk.tests.R index 7a2806d..5142a74 100644 --- a/R/random.walk.tests.R +++ b/R/random.walk.tests.R @@ -1,59 +1 @@ -random.walk.tests=function(x,B=64,Excursion=TRUE,Expansion=TRUE,Height=TRUE,alpha=0.05){ - - data=as.vector(x) - - if ((length(data)%%B)!=0){ - data=data[1:round(length(data)/B)] - } - result1=list(AD.result.Excursion=-1, KS.result.Excursion=-1, CS.result.Excursion=-1, AD.pvalue.Excursion=-1, - KS.pvalue.Excursion=-1, CS.pvalue.Excursion=-1, AD.statistic.Excursion=-1, KS.statistic.Excursion=-1, - CS.statistic.Excursion=-1) - result2=list(AD.result.Height=-1, KS.result.Height=-1, CS.result.Height=-1, AD.pvalue.Height=-1, - KS.pvalue.Height=-1, CS.pvalue.Height=-1, AD.statistic.Height=-1, KS.statistic.Height=-1, - CS.statistic.Height=-1) - result3=list(AD.result.Expansion=-1, KS.result.Expansion=-1, CS.result.Expansion=-1, AD.pvalue.Expansion=-1, - KS.pvalue.Expansion=-1, CS.pvalue.Expansion=-1, AD.statistic.Expansion=-1, KS.statistic.Expansion=-1, - CS.statistic.Expansion=-1) - - - if (Excursion==TRUE){ - if (sum(B==c(16, 32, 64, 128, 256))!=1){ - stop("The value of B must be in the set [16, 32, 64, 128, 256]!") - } - eeD=Random.walk.D(data,B) - test1=KSADCHRY(eeD$e,1,B,alpha) - result1=list(AD.result.Excursion=test1$sonucAD, KS.result.Excursion=test1$sonucKS, - AD.pvalue.Excursion=test1$ADtest[1,3], KS.pvalue.Excursion=test1$KStest[2], - AD.statistic.Excursion=test1$ADtest[1,1], KS.statistic.Excursion=test1$KStest[1], - CS.result.Excursion=test1$sonucKK,CS.pvalue.Excursion=test1$KKtest[2], - CS.statistic.Excursion=test1$KKtest[1]) - } - if (Height==TRUE){ - if (sum(B==c(64, 128, 256, 512, 1024))!=1){ - stop("The value of B must be in the set [64, 128, 256, 512, 1024]!") - } - eeY=Random.walk.Y(data,B) - test2=KSADCHRY(eeY$e,2,B,alpha) - result2=list(AD.result.Height=test2$sonucAD, KS.result.Height=test2$sonucKS, - AD.pvalue.Height=test2$ADtest[1,3], KS.pvalue.Height=test2$KStest[2], - AD.statistic.Height=test2$ADtest[1,1], KS.statistic.Height=test2$KStest[1], - CS.result.Height=test2$sonucKK,CS.pvalue.Height=test2$KKtest[2], - CS.statistic.Height=test2$KKtest[1]) - } - if (Expansion==TRUE){ - if (sum(B==c(32, 64, 128))!=1){ - stop("The value of B must be in the set [32, 64, 128]!") - } - eeG=Random.walk.G(data,B) - test3=KSADCHRY(eeG$e,3,B,alpha) - result3=list(AD.result.Expansion=test3$sonucAD,KS.result.Expansion=test3$sonucKS, - AD.pvalue.Expansion=test3$ADtest[1,3],KS.pvalue.Expansion=test3$KStest[2], - AD.statistic.Expansion=test3$ADtest[1,1],KS.statistic.Expansion=test3$KStest[1], - CS.result.Expansion=test3$sonucKK,CS.pvalue.Expansion=test3$KKtest[2], - CS.statistic.Expansion=test3$KKtest[1]) - } - - result=c(result1,result2,result3) - return(result) - -} \ No newline at end of file +random.walk.tests=function(x,B=64,Excursion=TRUE,Expansion=TRUE,Height=TRUE,alpha=0.05)UseMethod("random.walk.tests") \ No newline at end of file diff --git a/R/random.walk.tests.default.R b/R/random.walk.tests.default.R new file mode 100644 index 0000000..f4e40d0 --- /dev/null +++ b/R/random.walk.tests.default.R @@ -0,0 +1,9 @@ +random.walk.tests.default=function(x,B=64,Excursion=TRUE,Expansion=TRUE,Height=TRUE,alpha=0.05){ + options(warn=-1) + check(test=5,x=x,B=B,alpha=alpha,Excursion=Excursion,Expansion=Expansion,Height=Height) + + res.tbl=random.walk.tests.main(x,B=64,Excursion=TRUE,Expansion=TRUE,Height=TRUE,alpha=0.05) + res.tbl$call = match.call() + class(res.tbl) = c("random.walk.tests","CryptRndTest") + res.tbl +} \ No newline at end of file diff --git a/R/random.walk.tests.main.R b/R/random.walk.tests.main.R new file mode 100644 index 0000000..08d0bea --- /dev/null +++ b/R/random.walk.tests.main.R @@ -0,0 +1,59 @@ +random.walk.tests.main=function(x,B=64,Excursion=TRUE,Expansion=TRUE,Height=TRUE,alpha=0.05){ + + data=as.vector(x) + + if ((length(data)%%B)!=0){ + data=data[1:round(length(data)/B)] + } + result1=list(AD.result.Excursion=-1, KS.result.Excursion=-1, CS.result.Excursion=-1, AD.pvalue.Excursion=-1, + KS.pvalue.Excursion=-1, CS.pvalue.Excursion=-1, AD.statistic.Excursion=-1, KS.statistic.Excursion=-1, + CS.statistic.Excursion=-1) + result2=list(AD.result.Height=-1, KS.result.Height=-1, CS.result.Height=-1, AD.pvalue.Height=-1, + KS.pvalue.Height=-1, CS.pvalue.Height=-1, AD.statistic.Height=-1, KS.statistic.Height=-1, + CS.statistic.Height=-1) + result3=list(AD.result.Expansion=-1, KS.result.Expansion=-1, CS.result.Expansion=-1, AD.pvalue.Expansion=-1, + KS.pvalue.Expansion=-1, CS.pvalue.Expansion=-1, AD.statistic.Expansion=-1, KS.statistic.Expansion=-1, + CS.statistic.Expansion=-1) + + + if (Excursion==TRUE){ + if (sum(B==c(16, 32, 64, 128, 256))!=1){ + stop("The value of B must be in the set [16, 32, 64, 128, 256]!") + } + eeD=Random.walk.D(data,B) + test1=KSADCHRY(eeD$e,1,B,alpha) + result1=list(AD.result.Excursion=test1$sonucAD, KS.result.Excursion=test1$sonucKS, + AD.pvalue.Excursion=test1$ADtest[1,3], KS.pvalue.Excursion=test1$KStest[2], + AD.statistic.Excursion=test1$ADtest[1,1], KS.statistic.Excursion=test1$KStest[1], + CS.result.Excursion=test1$sonucKK,CS.pvalue.Excursion=test1$KKtest[2], + CS.statistic.Excursion=test1$KKtest[1]) + } + if (Height==TRUE){ + if (sum(B==c(64, 128, 256, 512, 1024))!=1){ + stop("The value of B must be in the set [64, 128, 256, 512, 1024]!") + } + eeY=Random.walk.Y(data,B) + test2=KSADCHRY(eeY$e,2,B,alpha) + result2=list(AD.result.Height=test2$sonucAD, KS.result.Height=test2$sonucKS, + AD.pvalue.Height=test2$ADtest[1,3], KS.pvalue.Height=test2$KStest[2], + AD.statistic.Height=test2$ADtest[1,1], KS.statistic.Height=test2$KStest[1], + CS.result.Height=test2$sonucKK,CS.pvalue.Height=test2$KKtest[2], + CS.statistic.Height=test2$KKtest[1]) + } + if (Expansion==TRUE){ + if (sum(B==c(32, 64, 128))!=1){ + stop("The value of B must be in the set [32, 64, 128]!") + } + eeG=Random.walk.G(data,B) + test3=KSADCHRY(eeG$e,3,B,alpha) + result3=list(AD.result.Expansion=test3$sonucAD,KS.result.Expansion=test3$sonucKS, + AD.pvalue.Expansion=test3$ADtest[1,3],KS.pvalue.Expansion=test3$KStest[2], + AD.statistic.Expansion=test3$ADtest[1,1],KS.statistic.Expansion=test3$KStest[1], + CS.result.Expansion=test3$sonucKK,CS.pvalue.Expansion=test3$KKtest[2], + CS.statistic.Expansion=test3$KKtest[1]) + } + + result=c(result1,result2,result3,list(name="RW",Exc=Excursion,Exp=Expansion,Hei=Height)) + return(result) + +} \ No newline at end of file diff --git a/R/topological.binary.R b/R/topological.binary.R index 9d74666..8bc5c6f 100644 --- a/R/topological.binary.R +++ b/R/topological.binary.R @@ -1,22 +1 @@ -topological.binary=function(x,B,alpha=0.05,critical.value){ - - n=length(x) - k=ceiling(n/B) - - blocks=array(NA,dim=c(k,B)) - blocks=matrix(unlist(split(x,k)),ncol=B,byrow = TRUE) - - num.different=nrow(unique(blocks)) - if (num.different<1){ - sonucTBT=0 - }else if (num.different>=min(k,2^B)){ - sonucTBT=1 - }else if (num.different=min(k,2^B)){ + sonucTBT=1 + }else if (num.different -} -\note{\bold{Acknowledgement:} The package \pkg{CryptRndTest} is based upon work supported by The Scientific and Technological Research Council of Turkey (TUBITAK) under Grant No. 114F249 of ARDEB-3001 grant. -} -\references{ - -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. -} - -\keyword{ Anderson-Darling, chi-Square, goodness-of-fit test, greatest common divisor, Stirling numbers of the second kind, Jarque-Bera, Kolmogorov-Smirnov, nonparametric, randomness test} - -\seealso{ -\code{\link[CryptRndTest]{adaptive.chi.square}}, \code{\link[CryptRndTest]{birthday.spacings}}, \code{\link[CryptRndTest]{book.stack}}, \code{\link[CryptRndTest]{GCD.test}}, \code{\link[CryptRndTest]{GCD}}, \code{\link[CryptRndTest]{GCD.q}}, \code{\link[CryptRndTest]{GCD.big}}, \code{\link[CryptRndTest]{random.walk.tests}}, \code{\link[CryptRndTest]{topological.binary}}, \code{\link[CryptRndTest]{Strlng2}}, \code{\link[copula]{Stirling2}} -} -\examples{ -# ----- 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(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(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 +\name{CryptRndTest-package} +\alias{CryptRndTest-package} +\alias{CryptRndTest} +\docType{package} +\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. 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. +} +\details{ +\tabular{ll}{ +Package: \tab CryptRndTest\cr +Type: \tab Package\cr +Version: \tab 1.2.1\cr +Date: \tab 2015-12-24\cr +License: \tab GPL-3\cr +} +To test statistical randomness of cryptographic randomness use functions \code{birthday.spacings} and \code{GCD.test} for testing sequences of integers, functions \code{adaptive.chi.square} and \code{book.stack} for testing sequences of integers or bits, and use functions \code{random.walk.tests} and \code{topological.binary} for testing sequences of bits. The function \code{random.walk.tests} performs random walk-excursion, random walk-expansion, and random walk-height tests. + +Additionally, use the function \code{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 \code{GCD} to compute GCD and the number iterations required to find GCD, recursively. Use the function \code{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 \code{Strlng2} to compute the Stirling numbers of the second kind in an approximate manner when the inputs are large. Use the function \code{TBT.criticalValue} to compute the critical value for the topological binary test at a given level of significance. Use the function \code{toBaseTwo} to convert integers (including big integers) from base 10 to 2. Use the function \code{toBaseTen} to convert binary sequences (including long binary sequences) from base 2 to 10. +} +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan +} +\note{\bold{Acknowledgement:} The package \pkg{CryptRndTest} is based upon work supported by The Scientific and Technological Research Council of Turkey (TUBITAK) under Grant No. 114F249 of ARDEB-3001 grant. +} +\references{ + +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. +} + +\keyword{ Anderson-Darling, chi-Square, goodness-of-fit test, greatest common divisor, Stirling numbers of the second kind, Jarque-Bera, Kolmogorov-Smirnov, nonparametric, randomness test} + +\seealso{ +\code{\link[CryptRndTest]{adaptive.chi.square}}, \code{\link[CryptRndTest]{birthday.spacings}}, \code{\link[CryptRndTest]{book.stack}}, \code{\link[CryptRndTest]{GCD.test}}, \code{\link[CryptRndTest]{GCD}}, \code{\link[CryptRndTest]{GCD.q}}, \code{\link[CryptRndTest]{GCD.big}}, \code{\link[CryptRndTest]{random.walk.tests}}, \code{\link[CryptRndTest]{topological.binary}}, \code{\link[CryptRndTest]{Strlng2}}, \code{\link[copula]{Stirling2}} +} +\examples{ +# ----- 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 } \ No newline at end of file diff --git a/man/GCD.test.Rd b/man/GCD.test.Rd index cb6a016..79c2c93 100644 --- a/man/GCD.test.Rd +++ b/man/GCD.test.Rd @@ -1,118 +1,119 @@ -\name{GCD.test} -\alias{GCD.test} - -\title{ -GCD Test -} -\description{ -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. -} -\usage{ -GCD.test(x, B = 32, KS = TRUE, CSQ = TRUE, AD = TRUE, JB = TRUE, - test.k = TRUE, test.g = TRUE, mu, sd, alpha = 0.05) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{x}{ - an \eqn{N*2} matrix of integers that includes random data. See details for further information. -} - \item{B}{ - the length of words (B-bit). -} - \item{KS}{ - if \code{TRUE}, Kolmogorov-Smirnov goodness-of-fit test is applied. -} - \item{CSQ}{ - if \code{TRUE}, Chi-Square goodness-of-fit test is applied. -} - \item{AD}{ - if \code{TRUE}, Anderson-Darling goodness-of-fit test is applied. -} - \item{JB}{ -if \code{TRUE}, Jarque-Bera goodness-of-fit test is applied. -} - \item{test.k}{ -if \code{TRUE}, randomness test is applied over the number of required iterations of the GCD operation. -} - \item{test.g}{ -if \code{TRUE}, randomness test is applied over the value of greatest common divisor. -} - \item{mu}{ - the mean of theoretical normal distribution that the number of required iterations follows. -} - \item{sd}{ - the standard deviation of theoretical normal distribution that the number of required iterations follows. -} - \item{alpha}{ - a predetermined value of type-I error with the default value of 0.05. -} -} -\details{ - -Total number of integers to be tested is divided into two sets and entered as \code{x}. The GCD operation is applied to each row of \code{x}. - - The number of required iterations follows a normal distribution with parameters \code{mu} and \code{sd}. Values of \code{mu} and \code{sd} are obtained by Monte Carlo simulation and given by Marsaglia and Tsang (2002) for 32-bit setting. We obtained values of \code{mu} and \code{sd} for other bit settings as \code{mu=4.2503, sd=1.650673} for 8-bits, \code{mu=8.8772, sd=2.38282} for 16-bits, ...for 24-bits,... - - -} -\value{ - -\item{sig.value.k}{ - a \eqn{4 x 1} vector of p-values. Elements of \code{sig.value.k} include p-value of Kolmogorov-Smirnov and Chi-Square tests, respectively. -} -\item{sig.value.g}{ - a \eqn{2 x 1} vector of p-values. Elements of \code{sig.value.g} include p-value of Kolmogorov-Smirnov, Chi-Square, Jarque-Bera, and Anderson-Darling tests, respectively. -} -\item{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. -} -\item{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. -} -\item{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. -} -\item{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. -} -\item{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. -} -\item{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. -} -} -\references{ -Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3). -} -\author{ -Haydar Demirhan - -Maintainer: Haydar Demirhan -} - -\seealso{ -See the function \code{\link{GCD}} that provides detailed results for the greatest common divisor operation. -} -\examples{ - -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 - - - -} -\keyword{Anderson-Darling } -\keyword{Jarque-Bera } -\keyword{Kolmogorov-Smirnov } -\keyword{Chi-Square } -\keyword{nonparametric } -\keyword{goodness-of-fit test } +\name{GCD.test} +\alias{GCD.test} + +\title{ +GCD Test +} +\description{ +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. +} +\usage{ +GCD.test(x, B = 32, KS = TRUE, CSQ = TRUE, AD = TRUE, JB = TRUE, + test.k = TRUE, test.g = TRUE, mu, sd, alpha = 0.05) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{x}{ + an \eqn{N*2} matrix of integers that includes random data. See details for further information. +} + \item{B}{ + the length of words (B-bit). +} + \item{KS}{ + if \code{TRUE}, Kolmogorov-Smirnov goodness-of-fit test is applied. +} + \item{CSQ}{ + if \code{TRUE}, Chi-Square goodness-of-fit test is applied. +} + \item{AD}{ + if \code{TRUE}, Anderson-Darling goodness-of-fit test is applied. +} + \item{JB}{ +if \code{TRUE}, Jarque-Bera goodness-of-fit test is applied. +} + \item{test.k}{ +if \code{TRUE}, randomness test is applied over the number of required iterations of the GCD operation. +} + \item{test.g}{ +if \code{TRUE}, randomness test is applied over the value of greatest common divisor. +} + \item{mu}{ + the mean of theoretical normal distribution that the number of required iterations follows. +} + \item{sd}{ + the standard deviation of theoretical normal distribution that the number of required iterations follows. +} + \item{alpha}{ + a predetermined value of significance level with the default value of 0.05. +} +} +\details{ + +Total number of integers to be tested is divided into two sets and entered as \code{x}. The GCD operation is applied to each row of \code{x}. + + The number of required iterations follows a normal distribution with parameters \code{mu} and \code{sd}. Values of \code{mu} and \code{sd} are obtained by Monte Carlo simulation and given by Marsaglia and Tsang (2002) for 32-bit setting. We obtained values of \code{mu} and \code{sd} for other bit settings as \code{mu=4.2503, sd=1.650673} for 8-bits, \code{mu=8.8772, sd=2.38282} for 16-bits, ...for 24-bits,... + + +} +\value{ + +\item{sig.value.k}{ + a \eqn{4 x 1} vector of p-values. Elements of \code{sig.value.k} include p-value of Kolmogorov-Smirnov and Chi-Square tests, respectively. +} +\item{sig.value.g}{ + a \eqn{2 x 1} vector of p-values. Elements of \code{sig.value.g} include p-value of Kolmogorov-Smirnov, Chi-Square, Jarque-Bera, and Anderson-Darling tests, respectively. +} +\item{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. +} +\item{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. +} +\item{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. +} +\item{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. +} +\item{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. +} +\item{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. +} +} +\references{ +Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3). +} +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan +} + +\seealso{ +See the function \code{\link{GCD}} that provides detailed results for the greatest common divisor operation. +} +\examples{ + +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) + +} +\keyword{Anderson-Darling } +\keyword{Jarque-Bera } +\keyword{Kolmogorov-Smirnov } +\keyword{Chi-Square } +\keyword{nonparametric } +\keyword{goodness-of-fit test } \keyword{randomness test } \ No newline at end of file diff --git a/man/adaptive.chi.square.Rd b/man/adaptive.chi.square.Rd index b052d99..3bce7b3 100644 --- a/man/adaptive.chi.square.Rd +++ b/man/adaptive.chi.square.Rd @@ -1,77 +1,77 @@ -\name{adaptive.chi.square} -\alias{adaptive.chi.square} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -Adaptive Chi-Square Test -} -\description{ -Performs Adaptive Chi-Square test of Ryabko et al.(2004) to evaluate the randomness of an RNG. -} -\usage{ -adaptive.chi.square(A, B, S, alpha = 0.05, prop=0.5, bit=FALSE) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - - \item{A}{ - a vector or matrix that includes random data. See details for further information. -} - \item{B}{ - the length of words (B-bit) that the chippered file will be divided into. -} - \item{S}{ - the number of subsets where letters of an alphabet are combined, and \eqn{S \ge 2} -} - \item{alpha}{ - a predetermined value of type-I error with the default value of 0.05. -} - \item{prop}{ - a predetermined value of proportion of training data set. -} -\item{bit}{ - if \code{A} contains a sequence of bits, \code{bit} is set \code{TRUE}. Otherwise, a sequence of integers is entered and \code{bit} is set \code{FALSE}. -} -} -\details{ -It is possible to apply adaptive Chi-Square to smaller samples than that required for the regular chi-square test. - -If \code{A} contains a sequence of bits, then \code{A} should be a matrix of \eqn{B}x\eqn{k}, where \eqn{k} is the number of words (integers) generated by the RNG of interest. Otherwise, \code{A} is a \eqn{k}x\eqn{1} 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 \code{S-1}. The value of \code{S} should be much less than \eqn{2^B}. -} -\value{ -\item{statistic}{ - calculated value of the test statistic. -} -\item{p.value}{ - p-value of the test. -} -\item{result.acsq}{ - returns 0 if H0 is rejected and 1 otherwise. -} -} -\references{ -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. -} -\author{ -Haydar Demirhan - -Maintainer: Haydar Demirhan -} - -\examples{ - -RNGkind(kind = "Super-Duper") -B=16 # Bit length is 16. -k=5000 # Generate 5000 integers. -A=0 -A=round(runif(k,0,(2^B-1))) -S=2 # Divide alphabet to two subsets. -alpha = 0.05 -test=adaptive.chi.square(A, B, S, alpha, bit =FALSE) -print(test) -} - -\keyword{goodness-of-fit test } -\keyword{randomness test }% __ONLY ONE__ keyword per line -\keyword{nonparametric } +\name{adaptive.chi.square} +\alias{adaptive.chi.square} +%- Also NEED an '\alias' for EACH other topic documented here. +\title{ +Adaptive Chi-Square Test +} +\description{ +Performs Adaptive Chi-Square test of Ryabko et al.(2004) to evaluate the randomness of an RNG. +} +\usage{ +adaptive.chi.square(x, B, S, alpha = 0.05, prop=0.5, bit=FALSE) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + + \item{x}{ + a vector or matrix that includes random data. See details for further information. +} + \item{B}{ + the length of words (B-bit) that the chippered file will be divided into. +} + \item{S}{ + the number of subsets where letters of an alphabet are combined, and \eqn{S \ge 2} +} + \item{alpha}{ + a predetermined value of significance level with the default value of 0.05. +} + \item{prop}{ + a predetermined value of proportion of training data set. +} +\item{bit}{ + if \code{x} contains a sequence of bits, \code{bit} is set \code{TRUE}. Otherwise, a sequence of integers is entered and \code{bit} is set \code{FALSE}. +} +} +\details{ +It is possible to apply adaptive Chi-Square to smaller samples than that required for the regular chi-square test. + +If \code{x} contains a sequence of bits, then \code{x} should be a matrix of \eqn{B}x\eqn{k}, where \eqn{k} is the number of words (integers) generated by the RNG of interest. Otherwise, \code{x} is a \eqn{k}x\eqn{1} 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 \code{S-1}. The value of \code{S} should be much less than \eqn{2^B}. +} +\value{ +\item{statistic}{ + calculated value of the test statistic. +} +\item{p.value}{ + p-value of the test. +} +\item{result.acsq}{ + returns 0 if H0 is rejected and 1 otherwise. +} +} +\references{ +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. +} +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan +} + +\examples{ + +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) +} + +\keyword{goodness-of-fit test } +\keyword{randomness test }% __ONLY ONE__ keyword per line +\keyword{nonparametric } diff --git a/man/birthday.spacings.Rd b/man/birthday.spacings.Rd index 2afd0ba..dde11ec 100644 --- a/man/birthday.spacings.Rd +++ b/man/birthday.spacings.Rd @@ -1,99 +1,99 @@ -\name{birthday.spacings} -\alias{birthday.spacings} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -Birthday Spacings Test -} -\description{ -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. -} -\usage{ -birthday.spacings(x, m = 128, n = 2^16, alpha = 0.05, lambda, num.class = 10) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{x}{ - a vector that includes random integers. -} - \item{m}{ - the number of birthdays. -} - \item{n}{ - the length of year. -} - \item{alpha}{ - a predetermined value of type-I error with the default value of 0.05. -} - \item{lambda}{ - mean of Poisson distribution that constitutes theoretical cumulative distribution function in goodness-of-fit tests. See Details section. -} - \item{num.class}{ - number of classes in the constructed frequency table for goodness-of-fit testing. -} -} -\details{ -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, \eqn{m} birthdays are randomly chosen from a year composed of \eqn{n} days. When the birthdays are sorted, asymptotic distribution of the number of duplicated values among the spacings between birthdays is Poisson with mean \eqn{\lambda=m^3/(4n)}. For most of the cases, this formula for \code{lambda} is useful. However, user should check suitability of the value entered for \code{lambda}. Note that some suitable values for \eqn{m} and \eqn{n} are given by Marsaglia and Tsang (2002). - -The argument \code{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. -} -\value{ -\item{AD.statistic}{ - calculated value of the test statistic of Anderson-Darling goodness-of-fit test. -} -\item{AD.pvalue}{ - p-value of the test of Anderson-Darling goodness-of-fit test. -} -\item{AD.result}{ - returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test. -} -\item{KS.statistic}{ - calculated value of the test statistic of Kolmogorov-Smirnov goodness-of-fit test. -} -\item{KS.pvalue}{ - p-value of the test of Kolmogorov-Smirnov goodness-of-fit test. -} -\item{KS.result}{ - returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test. -} -\item{CS.statistic}{ - calculated value of the test statistic of Chi-Square goodness-of-fit test. -} -\item{CS.pvalue}{ - p-value of the test of Chi-Square goodness-of-fit test. -} -\item{CS.result}{ - returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test. -} -} -\references{ -Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3). -} -\author{ -Haydar Demirhan - -Maintainer: Haydar Demirhan -} - -\examples{ - -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) - -} - -\keyword{Anderson-Darling } -\keyword{Kolmogorov-Smirnov } -\keyword{Chi-Square } -\keyword{nonparametric } -\keyword{goodness-of-fit test } +\name{birthday.spacings} +\alias{birthday.spacings} +%- Also NEED an '\alias' for EACH other topic documented here. +\title{ +Birthday Spacings Test +} +\description{ +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. +} +\usage{ +birthday.spacings(x, m = 128, n = 2^16, alpha = 0.05, lambda, num.class = 10) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{x}{ + a vector that includes random integers. +} + \item{m}{ + the number of birthdays. +} + \item{n}{ + the length of year. +} + \item{alpha}{ + a predetermined value of significance level with the default value of 0.05. +} + \item{lambda}{ + mean of Poisson distribution that constitutes theoretical cumulative distribution function in goodness-of-fit tests. See Details section. +} + \item{num.class}{ + number of classes in the constructed frequency table for goodness-of-fit testing. +} +} +\details{ +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, \eqn{m} birthdays are randomly chosen from a year composed of \eqn{n} days. When the birthdays are sorted, asymptotic distribution of the number of duplicated values among the spacings between birthdays is Poisson with mean \eqn{\lambda=m^3/(4n)}. For most of the cases, this formula for \code{lambda} is useful. However, user should check suitability of the value entered for \code{lambda}. Note that some suitable values for \eqn{m} and \eqn{n} are given by Marsaglia and Tsang (2002). + +The argument \code{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. +} +\value{ +\item{AD.statistic}{ + calculated value of the test statistic of Anderson-Darling goodness-of-fit test. +} +\item{AD.pvalue}{ + p-value of the test of Anderson-Darling goodness-of-fit test. +} +\item{AD.result}{ + returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test. +} +\item{KS.statistic}{ + calculated value of the test statistic of Kolmogorov-Smirnov goodness-of-fit test. +} +\item{KS.pvalue}{ + p-value of the test of Kolmogorov-Smirnov goodness-of-fit test. +} +\item{KS.result}{ + returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test. +} +\item{CS.statistic}{ + calculated value of the test statistic of Chi-Square goodness-of-fit test. +} +\item{CS.pvalue}{ + p-value of the test of Chi-Square goodness-of-fit test. +} +\item{CS.result}{ + returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test. +} +} +\references{ +Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3). +} +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan +} + +\examples{ + +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) + +} + +\keyword{Anderson-Darling } +\keyword{Kolmogorov-Smirnov } +\keyword{Chi-Square } +\keyword{nonparametric } +\keyword{goodness-of-fit test } \keyword{randomness test } \ No newline at end of file diff --git a/man/book.stack.Rd b/man/book.stack.Rd index eb6bfd8..11cb8c1 100644 --- a/man/book.stack.Rd +++ b/man/book.stack.Rd @@ -1,75 +1,75 @@ -\name{book.stack} -\alias{book.stack} - -\title{ -Book Stack Test -} - -\description{ -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. -} - -\usage{ -book.stack(A, B, k=2, alpha=0.05, bit=FALSE) -} - -\arguments{ - \item{A}{ - a vector or matrix that includes random data. See details for further information. -} - \item{B}{ - the length of words (B-bit) that the chippered file will be divided. -} - \item{k}{ - the number of subsets that the alphabet will be divided. It should be chosen to ensure \eqn{|A|/k} will be an integer. -} - \item{alpha }{ - a predetermined value of type-I error with the default value of 0.05. -} -\item{bit}{ - if \code{A} contains a sequence of bits, \code{bit} is set \code{TRUE}. Otherwise, a sequence of integers is entered and \code{bit} is set \code{FALSE}. -} -} -\details{ - If \code{A} contains a sequence of bits, then \code{A} should be a matrix of \eqn{B}x\eqn{N}, where \eqn{N} is the number of words (integers) generated by the RNG of interest. Otherwise, \code{A} is an \eqn{N}x\eqn{1} 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 \eqn{N}, 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 (\eqn{n}) that is given by Ryabko and Monarev (2005) as \eqn{n=B(2^(B/2))}. For example, if \eqn{B=16}, then \eqn{n=4096} and the legth of alphabet is 65536. In this case, we need to enter 4096 bits or \eqn{N=4096/16=256} integers. However, under the setting \eqn{B=32}, the length of alphabet is 2^32 and we need to enter 65536. Note that it is hard to implement the test under the latter setting due to the memory overflows. Therefore, this test is applicable for smaller values of \eqn{B} than 32-bits. - In this test, because there is no asymptotic theoretical distribution introduced, only chi-square test is applied as goodness-of-fit test. -} -\value{ -\item{statistic }{ - calculated value of the test statistic. -} -\item{p.value }{ - p-value of the Chi-Square test. -} -\item{BS.result }{ - returns 0 if H0 is rejected and 1 otherwise. -} -} -\references{ -Ryabko, B.Ya., Monarev, V.A., Using information theory approach to randomness testing. Journal of Statistical Planning and Inference (2005), 133, 95--110. -} -\author{ -Haydar Demirhan - -Maintainer: Haydar Demirhan -} - -\examples{ - -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. -A=round(runif(N,0,(2^B-1))) -k=2 # Divide alphabet to two sub-sets. -alpha=0.05 -test=book.stack(A, B, k, alpha, bit = FALSE) -print(test) - -} - -\keyword{Chi-Square } -\keyword{nonparametric } -\keyword{goodness-of-fit test } +\name{book.stack} +\alias{book.stack} + +\title{ +Book Stack Test +} + +\description{ +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. +} + +\usage{ +book.stack(x, B, k=2, alpha=0.05, bit=FALSE) +} + +\arguments{ + \item{x}{ + a vector or matrix that includes random data. See details for further information. +} + \item{B}{ + the length of words (B-bit) that the chippered file will be divided. +} + \item{k}{ + the number of subsets that the alphabet will be divided. It should be chosen to ensure \eqn{|x|/k} will be an integer. +} + \item{alpha }{ + a predetermined value of significance level with the default value of 0.05. +} +\item{bit}{ + if \code{x} contains a sequence of bits, \code{bit} is set \code{TRUE}. Otherwise, a sequence of integers is entered and \code{bit} is set \code{FALSE}. +} +} +\details{ + If \code{x} contains a sequence of bits, then \code{x} should be a matrix of \eqn{B}x\eqn{N}, where \eqn{N} is the number of words (integers) generated by the RNG of interest. Otherwise, \code{x} is an \eqn{N}x\eqn{1} 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 \eqn{N}, 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 (\eqn{n}) that is given by Ryabko and Monarev (2005) as \eqn{n=B(2^(B/2))}. For example, if \eqn{B=16}, then \eqn{n=4096} and the legth of alphabet is 65536. In this case, we need to enter 4096 bits or \eqn{N=4096/16=256} integers. However, under the setting \eqn{B=32}, the length of alphabet is 2^32 and we need to enter 65536. Note that it is hard to implement the test for \eqn{B>32} due to the memory overflows. Therefore, this test is applicable for smaller values of \eqn{B}. + In this test, because there is no asymptotic theoretical distribution introduced, only chi-square test is applied as goodness-of-fit test. +} +\value{ +\item{statistic }{ + calculated value of the test statistic. +} +\item{p.value }{ + p-value of the Chi-Square test. +} +\item{BS.result }{ + returns 0 if H0 is rejected and 1 otherwise. +} +} +\references{ +Ryabko, B.Ya., Monarev, V.A., Using information theory approach to randomness testing. Journal of Statistical Planning and Inference (2005), 133, 95--110. +} +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan +} + +\examples{ + +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) + +} + +\keyword{Chi-Square } +\keyword{nonparametric } +\keyword{goodness-of-fit test } \keyword{randomness test } \ No newline at end of file diff --git a/man/print.CryptRndTest.Rd b/man/print.CryptRndTest.Rd new file mode 100644 index 0000000..cf264f7 --- /dev/null +++ b/man/print.CryptRndTest.Rd @@ -0,0 +1,26 @@ +\name{print.CryptRndTest} +\alias{print.CryptRndTest} +\title{ +Print Test Results +} +\description{ +Prints a summary of test results. +} +\usage{ +\method{print}{CryptRndTest}(x,...) +} +\arguments{ + \item{x}{ +an object including information to be printed. +} + \item{...}{ +other arguments. +} +} + +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan + +} \ No newline at end of file diff --git a/man/random.walk.tests.Rd b/man/random.walk.tests.Rd index 8a40c60..c18d9f4 100644 --- a/man/random.walk.tests.Rd +++ b/man/random.walk.tests.Rd @@ -1,151 +1,151 @@ -\name{random.walk.tests} -\alias{random.walk.tests} -\title{ -Random Walk Tests -} -\description{ -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. -} -\usage{ -random.walk.tests(x, B = 64, Excursion = TRUE, Expansion = TRUE, - Height = TRUE, alpha = 0.05) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{x}{ - a matrix that includes random data in base-2 format. See details for further information. -} - \item{B}{ - the length of words (B-bit). See Details section. -} - \item{Excursion}{ - if \code{TRUE}, Random Walk Excursion test is applied. -} - \item{Expansion}{ - if \code{TRUE}, Random Walk Expansion test is applied. -} - \item{Height}{ - if \code{TRUE}, Random Walk Height test is applied. -} - \item{alpha}{ - a predetermined value of type-I error with the default value of 0.05. -} -} -\details{ -Argument \code{x} should be entered as a matrix of bits of dimension \eqn{B}x\eqn{k}, where \eqn{k} 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 Expansion is TRUE, B takes 64, 128, 256, 512, and 1024. If Height is TRUE, B takes 32, 64, and 128. Because theoretical cumulative distribution functions for the other word lengths, \code{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. -} -\value{ - -\item{AD.statistic.Excursion}{ - value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Excursion procedure. -} -\item{KS.statistic.Excursion}{ - value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Excursion procedure. -} -\item{CS.statistic.Excursion}{ - value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Excursion procedure. -} -\item{AD.pvalue.Excursion}{ - p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Excursion procedure. -} -\item{KS.pvalue.Excursion}{ - p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Excursion procedure. -} -\item{CS.pvalue.Excursion}{ - p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Excursion procedure. -} -\item{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. -} -\item{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. -} -\item{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. -} - -\item{AD.statistic.Expansion}{ - value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Expansion procedure. -} -\item{KS.statistic.Expansion}{ - value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Expansion procedure. -} -\item{CS.statistic.Expansion}{ - value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Expansion procedure. -} -\item{AD.pvalue.Expansion}{ - p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Expansion procedure. -} -\item{KS.pvalue.Expansion}{ - p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Expansion procedure. -} -\item{CS.pvalue.Expansion}{ - p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Expansion procedure. -} -\item{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. -} -\item{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. -} -\item{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. -} - -\item{AD.statistic.Height}{ - value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Height procedure. -} -\item{KS.statistic.Height}{ - value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Height procedure. -} -\item{CS.statistic.Height}{ - value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Height procedure. -} -\item{AD.pvalue.Height}{ - p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Height procedure. -} -\item{KS.pvalue.Height}{ - p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Height procedure. -} -\item{CS.pvalue.Height}{ - p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Height procedure. -} -\item{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. -} -\item{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. -} -\item{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. -} -} -\references{ -Doganaksoy, A., Calik, C., Sulak, F., Turan, M.S., New randomness tests using random walk, In: National Cryptology Symposium II, (2006), Ankara, Turkey. -} -\author{ -Haydar Demirhan - -Maintainer: Haydar Demirhan -} - -\examples{ - -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) - -} -\keyword{Anderson-Darling } -\keyword{Kolmogorov-Smirnov } -\keyword{Chi-Square } -\keyword{nonparametric } -\keyword{goodness-of-fit test } +\name{random.walk.tests} +\alias{random.walk.tests} +\title{ +Random Walk Tests +} +\description{ +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. +} +\usage{ +random.walk.tests(x, B = 64, Excursion = TRUE, Expansion = TRUE, + Height = TRUE, alpha = 0.05) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{x}{ + a matrix that includes random data in base-2 format. See details for further information. +} + \item{B}{ + the length of words (B-bit). See Details section. +} + \item{Excursion}{ + if \code{TRUE}, Random Walk Excursion test is applied. +} + \item{Expansion}{ + if \code{TRUE}, Random Walk Expansion test is applied. +} + \item{Height}{ + if \code{TRUE}, Random Walk Height test is applied. +} + \item{alpha}{ + a predetermined value of significance level with the default value of 0.05. +} +} +\details{ +Argument \code{x} should be entered as a matrix of bits of dimension \eqn{B}x\eqn{k}, where \eqn{k} is the number of words (integers) generated by the RNG of interest. + +If \code{Excursion} is TRUE, B takes the values 16, 32, 64, 128, and 256. If \code{Height} is TRUE, B takes 64, 128, 256, 512, and 1024. If \code{Expansion} is TRUE, B takes 32, 64, and 128. Because theoretical cumulative distribution functions for the other word lengths, \code{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. +} +\value{ + +\item{AD.statistic.Excursion}{ + value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Excursion procedure. +} +\item{KS.statistic.Excursion}{ + value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Excursion procedure. +} +\item{CS.statistic.Excursion}{ + value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Excursion procedure. +} +\item{AD.pvalue.Excursion}{ + p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Excursion procedure. +} +\item{KS.pvalue.Excursion}{ + p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Excursion procedure. +} +\item{CS.pvalue.Excursion}{ + p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Excursion procedure. +} +\item{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. +} +\item{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. +} +\item{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. +} + +\item{AD.statistic.Expansion}{ + value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Expansion procedure. +} +\item{KS.statistic.Expansion}{ + value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Expansion procedure. +} +\item{CS.statistic.Expansion}{ + value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Expansion procedure. +} +\item{AD.pvalue.Expansion}{ + p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Expansion procedure. +} +\item{KS.pvalue.Expansion}{ + p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Expansion procedure. +} +\item{CS.pvalue.Expansion}{ + p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Expansion procedure. +} +\item{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. +} +\item{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. +} +\item{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. +} + +\item{AD.statistic.Height}{ + value of test statistic of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Height procedure. +} +\item{KS.statistic.Height}{ + value of test statistic of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Height procedure. +} +\item{CS.statistic.Height}{ + value of test statistic of Chi-Square goodness-of-fit test conducted after application of Random Walk Height procedure. +} +\item{AD.pvalue.Height}{ + p-value of Anderson-Darling goodness-of-fit test conducted after application of Random Walk Height procedure. +} +\item{KS.pvalue.Height}{ + p-value of Kolmogorov-Smirnov goodness-of-fit test conducted after application of Random Walk Height procedure. +} +\item{CS.pvalue.Height}{ + p-value of Chi-Square goodness-of-fit test conducted after application of Random Walk Height procedure. +} +\item{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. +} +\item{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. +} +\item{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. +} +} +\references{ +Doganaksoy, A., Calik, C., Sulak, F., Turan, M.S., New randomness tests using random walk, In: National Cryptology Symposium II, (2006), Ankara, Turkey. +} +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan +} + +\examples{ + +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) + +} +\keyword{Anderson-Darling } +\keyword{Kolmogorov-Smirnov } +\keyword{Chi-Square } +\keyword{nonparametric } +\keyword{goodness-of-fit test } \keyword{randomness test } \ No newline at end of file diff --git a/man/topological.binary.Rd b/man/topological.binary.Rd index 0669282..20c5f86 100644 --- a/man/topological.binary.Rd +++ b/man/topological.binary.Rd @@ -1,65 +1,65 @@ -\name{topological.binary} -\alias{topological.binary} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -Topological Binary Test -} -\description{ - 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. -} -\usage{ -topological.binary(x, B, alpha = 0.05, critical.value) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{x}{ - a matrix that includes random data in base-2 format. See details for further information. -} - \item{B}{ - the length of words (B-bit). -} - \item{alpha}{ - a predetermined value of type-I error with the default value of 0.05. -} - \item{critical.value}{ - a value used to decide whether to reject the null hypothesis at the significance level of \code{alpha}. See details for further information. -} -} -\details{ -The argument \code{x} should be entered as a matrix of bits of dimension \eqn{B}x\eqn{k}, where \eqn{k} is the number of words (integers) generated by the RNG of interest. - -The argument \code{critical.value} should be calculated regarding the value of \code{B}. For \eqn{B = 8,...,16}, values of \code{critical.value} are tabulated by Alcover et al. (2013) and calculation procedure of \code{critical.value} for the values greater than 16 is described therein. The tabulated values can be used if the number of words (\eqn{k}) is equal to \eqn{2^B}. Otherwise, it should be calculated over the given cumulative distribution function by Alcover et al. (2013). For example, if \eqn{k=10^4}, then \code{critical.value}\eqn{ = 9245} and if \eqn{k=2*10^4}, then \code{critical.value}\eqn{ = 19999}. - -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. -} -\value{ -\item{statistic}{ - calculated value of the test statistic. -} -\item{result.TBT}{ - returns 0 if H0 is rejected and 1 otherwise. -} -} -\references{ -Alcover, P.M., Guillamon, A., Ruiz, M.C., A new randomness test for bit sequences. Informatica (2013), 24(3), 339--356. -} -\author{ -Haydar Demirhan - -Maintainer: Haydar Demirhan -} - -\examples{ -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) -} -\keyword{nonparametric } +\name{topological.binary} +\alias{topological.binary} +%- Also NEED an '\alias' for EACH other topic documented here. +\title{ +Topological Binary Test +} +\description{ + 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. +} +\usage{ +topological.binary(x, B, alpha = 0.05, critical.value) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{x}{ + a matrix that includes random data in base-2 format. See details for further information. +} + \item{B}{ + the length of words (B-bit). +} + \item{alpha}{ + a predetermined value of significance level with the default value of 0.05. +} + \item{critical.value}{ + a value used to decide whether to reject the null hypothesis at the significance level of \code{alpha}. See details for further information. +} +} +\details{ +The argument \code{x} should be entered as a matrix of bits of dimension \eqn{B}x\eqn{k}, where \eqn{k} is the number of words (integers) generated by the RNG of interest. + +The argument \code{critical.value} should be calculated regarding the value of \code{B}. For \eqn{B = 8,...,16}, values of \code{critical.value} are tabulated by Alcover et al. (2013) and calculation procedure of \code{critical.value} for the values greater than 16 is described therein. The tabulated values can be used if the number of words (\eqn{k}) is equal to \eqn{2^B}. Otherwise, it should be calculated over the given cumulative distribution function by Alcover et al. (2013). For example, if \eqn{k=10^4}, then \code{critical.value}\eqn{ = 9245} and if \eqn{k=2*10^4}, then \code{critical.value}\eqn{ = 19999}. + +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. +} +\value{ +\item{statistic}{ + calculated value of the test statistic. +} +\item{result.TBT}{ + returns 0 if H0 is rejected and 1 otherwise. +} +} +\references{ +Alcover, P.M., Guillamon, A., Ruiz, M.C., A new randomness test for bit sequences. Informatica (2013), 24(3), 339--356. +} +\author{ +Haydar Demirhan + +Maintainer: Haydar Demirhan +} + +\examples{ +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) +} +\keyword{nonparametric } \keyword{randomness test } \ No newline at end of file