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
8d647ce
commit e2ce8af
Showing
35 changed files
with
1,628 additions
and
1,057 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,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 <haydarde@hacettepe.edu.tr> | ||
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 |
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,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 |
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,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) |
This file was deleted.
Oops, something went wrong.
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,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]<alpha){ | ||
KS.result.k=0 | ||
}else { | ||
KS.result.k=1 | ||
} | ||
} | ||
if (CSQ==TRUE){ | ||
nbin=min(length(tabulate(teorik.Normal)),length(tabulate(y))) | ||
gozl=tabulate(y,nbins=nbin) | ||
bekl=tabulate(teorik.Normal,nbins=nbin) | ||
gozl[which(gozl==0)]=10^-5 | ||
bekl[which(bekl==0)]=10^-5 | ||
testCSQ.p.value=pchisq(sum((gozl-bekl)^2/bekl), df=nbin-1, ncp = 0, lower.tail = FALSE, log.p = FALSE) | ||
sig.value.k[2]=testCSQ.p.value | ||
if (sig.value.k[2]<alpha){ | ||
CSQ.result.k=0 | ||
}else { | ||
CSQ.result.k=1 | ||
} | ||
} | ||
if (JB==TRUE){ | ||
testJB= jarque.bera.test(as.matrix((y-mean(y))/sd(y))) | ||
sig.value.k[3]=testJB$p.value | ||
if (sig.value.k[3]<alpha){ | ||
JB.result.k=0 | ||
}else { | ||
JB.result.k=1 | ||
} | ||
} | ||
if (AD==TRUE){ | ||
if (N>=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]<alpha){ | ||
AD.result.k=0 | ||
}else { | ||
AD.result.k=1 | ||
} | ||
} | ||
} | ||
|
||
if (test.g==TRUE){ | ||
kuramsalDF=0 | ||
teo=0 | ||
teorik=0 | ||
rasgele=runif(N,0,1) | ||
bsl=1 | ||
i=0 | ||
while ((sum(teo)<N)){ | ||
i=i+1 | ||
kuramsalDF[i]=0 | ||
j=1:i | ||
kuramsalDF[i]=sum(6/((pi*j)^2)) | ||
if (kuramsalDF[i]==0){ | ||
kuramsalDF[i]=1 | ||
} | ||
if (i==1){ | ||
teo[i]=sum(rasgele<=kuramsalDF[i]) | ||
teorik[bsl:(bsl+teo[i]-1)]=3 | ||
bsl=bsl+teo[i] | ||
}else{ | ||
teo[i]=sum(rasgele<=kuramsalDF[i])-sum(teo[1:i-1]) | ||
if (i>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]<alpha){ | ||
KS.result.g=0 | ||
}else { | ||
KS.result.g=1 | ||
} | ||
} | ||
if (CSQ==TRUE){ | ||
test2=chisq.test(y2, teorik, correct = FALSE) | ||
sig.value.g[2]=test2$p.value | ||
if (sig.value.g[2]<alpha){ | ||
CSQ.result.g=0 | ||
}else { | ||
CSQ.result.g=1 | ||
} | ||
} | ||
} | ||
|
||
if ((test.g==TRUE) & (test.k==TRUE)) { | ||
result=list(sig.value.k=sig.value.k,sig.value.g=sig.value.g,KS.result.k=KS.result.k,CSQ.result.k=CSQ.result.k, | ||
AD.result.k=AD.result.k,JB.result.k=JB.result.k,KS.result.g=KS.result.g,CSQ.result.g=CSQ.result.g) | ||
}else if ((test.g==TRUE) & (test.k==FALSE)) { | ||
result=list(sig.value.g=sig.value.g,KS.result.g=KS.result.g,CSQ.result.g=CSQ.result.g) | ||
}else if ((test.g==FALSE) & (test.k==TRUE)) { | ||
result=list(sig.value.k=sig.value.k,KS.result.k=KS.result.k,CSQ.result.k=CSQ.result.k,AD.result.k=AD.result.k, | ||
JB.result.k=JB.result.k) | ||
} | ||
return(result) | ||
} | ||
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) UseMethod("GCD.test") |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
GCD.test.default=function(x,B=32,KS=TRUE,CSQ=TRUE,AD=TRUE,JB=TRUE,test.k=TRUE,test.g=TRUE,mu,sd,alpha=0.05){ | ||
options(warn=-1) | ||
check(test=4,x=x,B=B,alpha=alpha,KS=KS,CSQ=CSQ,AD=AD,JB=JB,test.k=test.k,test.g=test.g,mu=mu,sd=sd) | ||
|
||
res.tbl=GCD.test.main(x=x,B=B,KS=KS,CSQ=CSQ,AD=AD,JB=JB,test.k=test.k,test.g=test.g,mu=mu,sd=sd,alpha=alpha) | ||
res.tbl$call = match.call() | ||
class(res.tbl) = c("GCD.test","CryptRndTest") | ||
res.tbl | ||
} |
Oops, something went wrong.