Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2ce8af
commit e43f966
Showing
12 changed files
with
2,759 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
Package: CryptRndTest | ||
Type: Package | ||
Title: Statistical Tests for Cryptographic Randomness | ||
Version: 1.2.1 | ||
Date: 2015-12-24 | ||
Author: Haydar Demirhan | ||
Version: 1.2.2 | ||
Date: 2016-02-24 | ||
Author: Haydar Demirhan | ||
Maintainer: Haydar Demirhan <haydarde@hacettepe.edu.tr> | ||
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. | ||
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 | ||
Suggests: R.rsp | ||
VignetteBuilder: R.rsp | ||
License: GPL-3 | ||
RoxygenNote: 5.0.1 | ||
NeedsCompilation: no | ||
Packaged: 2016-01-04 14:02:49 UTC; Stat | ||
Packaged: 2016-02-25 00:43:41 UTC; e27752 | ||
Repository: CRAN | ||
Date/Publication: 2016-01-04 15:28:45 | ||
Date/Publication: 2016-02-25 05:21:43 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,49 @@ | ||
exportPattern("^[[:alpha:]]+") | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
importFrom(sfsmisc,digitsBase) | ||
|
||
importFrom(tseries,jarque.bera.test) | ||
|
||
importFrom(kSamples,ad.test) | ||
|
||
importFrom(MissMech,AndersonDarling) | ||
|
||
importFrom(LambertW,W) | ||
|
||
importFrom(gmp,Stirling2) | ||
|
||
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(GCD.test,main) | ||
S3method(adaptive.chi.square,default) | ||
S3method(adaptive.chi.square,main) | ||
|
||
S3method(birthday.spacings,default) | ||
S3method(birthday.spacings,main) | ||
|
||
S3method(book.stack,default) | ||
S3method(book.stack,main) | ||
|
||
S3method(GCD.test,main) | ||
|
||
S3method(print,CryptRndTest) | ||
S3method(random.walk.tests,default) | ||
S3method(random.walk.tests,main) | ||
S3method(topological.binary,default) | ||
S3method(topological.binary,main) | ||
|
||
S3method(print,CryptRndTest) | ||
export(GCD) | ||
export(GCD.big) | ||
export(GCD.q) | ||
export(GCD.test) | ||
export(Strlng2) | ||
export(TBT.criticalValue) | ||
export(adaptive.chi.square) | ||
export(birthday.spacings) | ||
export(book.stack) | ||
export(random.walk.tests) | ||
export(toBaseTen) | ||
export(toBaseTwo) | ||
export(topological.binary) | ||
importFrom(LambertW,W) | ||
importFrom(MissMech,AndersonDarling) | ||
importFrom(Rmpfr,mpfr) | ||
importFrom(Rmpfr,mpfrArray) | ||
importFrom(gmp,Stirling2) | ||
importFrom(kSamples,ad.test) | ||
importFrom(methods,new) | ||
importFrom(parallel,clusterExport) | ||
importFrom(parallel,makePSOCKcluster) | ||
importFrom(parallel,parLapply) | ||
importFrom(parallel,setDefaultCluster) | ||
importFrom(parallel,stopCluster) | ||
importFrom(sfsmisc,digitsBase) | ||
importFrom(stats,chisq.test) | ||
importFrom(stats,dpois) | ||
importFrom(stats,ks.test) | ||
importFrom(stats,pchisq) | ||
importFrom(stats,rnorm) | ||
importFrom(stats,runif) | ||
importFrom(tseries,jarque.bera.test) | ||
importFrom(utils,write.table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,96 @@ | ||
KSADdga=function(e,alfa,n,m,lambda,num.class=10){ | ||
z=0 | ||
expected=0 | ||
p=0 | ||
p[1:(num.class+1)]=dpois(0:num.class,lambda=lambda) | ||
p[num.class+1]=p[num.class+1]+sum(dpois((num.class+1):1000,lambda=lambda)) | ||
N=length(e) | ||
expected=round(p*N) | ||
if (sum(expected)!=N){ | ||
expected[which.max(expected)]=expected[which.max(expected)]-(sum(expected)-N) | ||
} | ||
z=rep(0:(length(expected)-1),expected) | ||
test=kSamples::ad.test(e,z,method="simulated",dist=FALSE,Nsim=1000) | ||
ADtest=test$ad | ||
if (min(ADtest[,3])<alfa){ | ||
sonucAD=0 | ||
} else{ | ||
sonucAD=1 | ||
} | ||
|
||
KStest=0 | ||
test2=ks.test(e,z) | ||
KStest[1]=test2$statistic | ||
KStest[2]=test2$p.value | ||
if (KStest[2]<alfa){ | ||
sonucKS=0 | ||
} else{ | ||
sonucKS=1 | ||
} | ||
|
||
k=length(expected) | ||
observed=array(0,k) | ||
observed[1:length(table(e))]=table(e) | ||
KKtest=0 | ||
observed[which(observed==0)]=10^-5 | ||
expected[which(expected==0)]=10^-5 | ||
KKtest[1]=sum(((observed-expected)^2)/expected,na.rm=TRUE) #gives test statistic | ||
KKtest[2]=pchisq(KKtest[1],(k-1),lower.tail=FALSE) #gives p.value of the chi-square test | ||
if (KKtest[2]<alfa){ | ||
sonucKK=0 | ||
} else{ | ||
sonucKK=1 | ||
} | ||
result=list(sonucAD=sonucAD,ADtest=ADtest,sonucKS=sonucKS,KStest=KStest,sonucKK=sonucKK,KKtest=KKtest) | ||
return(result) | ||
#' @importFrom stats ks.test | ||
#' @importFrom stats chisq.test | ||
#' @importFrom stats dpois | ||
#' @importFrom stats pchisq | ||
#' @importFrom stats rnorm | ||
#' @importFrom stats runif | ||
#' @importFrom parallel parLapply | ||
#' @importFrom parallel clusterExport | ||
#' @importFrom parallel setDefaultCluster | ||
#' @importFrom parallel stopCluster | ||
#' @importFrom parallel makePSOCKcluster | ||
#' @importFrom Rmpfr mpfrArray | ||
#' @importFrom Rmpfr mpfr | ||
#' @importFrom gmp Stirling2 | ||
#' @importFrom LambertW W | ||
#' @importFrom MissMech AndersonDarling | ||
#' @importFrom kSamples ad.test | ||
#' @importFrom tseries jarque.bera.test | ||
#' @importFrom sfsmisc digitsBase | ||
#' @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 | ||
|
||
#' @export adaptive.chi.square | ||
#' @export birthday.spacings | ||
#' @export book.stack | ||
#' @export GCD.test | ||
#' @export random.walk.tests | ||
#' @export topological.binary | ||
#' @export GCD | ||
#' @export GCD.big | ||
#' @export GCD.q | ||
#' @export Strlng2 | ||
#' @export TBT.criticalValue | ||
#' @export toBaseTen | ||
#' @export toBaseTwo | ||
|
||
KSADdga=function(e,alfa,n,m,lambda,num.class=10){ | ||
z=0 | ||
expected=0 | ||
p=0 | ||
p[1:(num.class+1)]=dpois(0:num.class,lambda=lambda) | ||
p[num.class+1]=p[num.class+1]+sum(dpois((num.class+1):1000,lambda=lambda)) | ||
N=length(e) | ||
expected=round(p*N) | ||
if (sum(expected)!=N){ | ||
expected[which.max(expected)]=expected[which.max(expected)]-(sum(expected)-N) | ||
} | ||
z=rep(0:(length(expected)-1),expected) | ||
test=kSamples::ad.test(e,z,method="simulated",dist=FALSE,Nsim=1000) | ||
ADtest=test$ad | ||
if (min(ADtest[,3])<alfa){ | ||
sonucAD=0 | ||
} else{ | ||
sonucAD=1 | ||
} | ||
|
||
KStest=0 | ||
test2=ks.test(e,z) | ||
KStest[1]=test2$statistic | ||
KStest[2]=test2$p.value | ||
if (KStest[2]<alfa){ | ||
sonucKS=0 | ||
} else{ | ||
sonucKS=1 | ||
} | ||
|
||
k=length(expected) | ||
observed=array(0,k) | ||
observed[1:length(table(e))]=table(e) | ||
KKtest=0 | ||
observed[which(observed==0)]=10^-5 | ||
expected[which(expected==0)]=10^-5 | ||
KKtest[1]=sum(((observed-expected)^2)/expected,na.rm=TRUE) #gives test statistic | ||
KKtest[2]=pchisq(KKtest[1],(k-1),lower.tail=FALSE) #gives p.value of the chi-square test | ||
if (KKtest[2]<alfa){ | ||
sonucKK=0 | ||
} else{ | ||
sonucKK=1 | ||
} | ||
result=list(sonucAD=sonucAD,ADtest=ADtest,sonucKS=sonucKS,KStest=KStest,sonucKK=sonucKK,KKtest=KKtest) | ||
return(result) | ||
} |
Binary file not shown.
Oops, something went wrong.