Friday, 18 May 2012

DiceLockSecurity Knowledge

Windows - Source Code

Linux - Source Code

Apple Mac OS X

JAVA - Source Code

DOCUMENTATION - Inside Knowledge

DOCUMENTATION - Self browser view

HOW TO

arrow DiceChecker 3.0.0.1 arrow overlappingTemplateMatchingsTest.cpp
overlappingTemplateMatchingsTest.cpp Print E-mail
Get C++ and Java source code with ready to use project files for Microsoft Visual Studio for Windows, Oracle JDeveloper for Java JRE, Xcode for Mac OS X and Eclipse CDT with Nokia QT for Linux ...
VisualStudio.pngjdeveloper.pngXcode.pngeclipse-cdt.pngqt.png
Retired Content
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

As per NIST FIPS 800-22b Get FREE C++ Source Code

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
//
// Creator:    http://www.dicelocksecurity.com
// Version:    vers.3.0.0.1
//
// Copyright © 2008-2010 DiceLock Security, LLC. All rights reserved.
//
//                               DISCLAIMER
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// 
// DICELOCK IS A REGISTERED TRADEMARK OR TRADEMARK OF THE OWNERS
// 
 
#include <stdexcept>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include "overlappingTemplateMatchingsTest.h"
 
 
using namespace std;
 
 
namespace DiceLockSecurity {
  
  namespace RandomTest {
 
  // Random Test Class enumerator name
  const RandomTests OverlappingTemplateMatchingsTest::test = OverlappingTemplateMatchings;
  // Random Test Class minimum stream length
  const unsigned int  OverlappingTemplateMatchingsTest::minimumLength = 1000000;
 
  // Random Test Class block sizes
  const short  OverlappingTemplateMatchingsTest::numberWindowLengths = 2;
  const short  OverlappingTemplateMatchingsTest::windowLengths[2] = {9, 10};
 
  const int OverlappingTemplateMatchingsTest::NumAssignments = 6;  
  const int OverlappingTemplateMatchingsTest::OverlappingStringTested = 1032;
 
  // Constructor, default 
  OverlappingTemplateMatchingsTest::OverlappingTemplateMatchingsTest() {
    int i;
 
    windowLength = 0; 
    substringLength = 0;
    substringNumber = 0;
    chiSquared = 0.0;
    eta = 0.0;
    lambda = 0.0;
    for (i=0; i<NumAssignments; i++)
      assignment[i] = 0;
  }
 
  // Constructor with a MathematicalFunctions object instantiated 
  OverlappingTemplateMatchingsTest::OverlappingTemplateMatchingsTest(MathematicalFunctions* mathFuncObj) {
    int i;
 
    windowLength = 0; 
    substringLength = 0;
    substringNumber = 0;
    chiSquared = 0.0;
    eta = 0.0;
    lambda = 0.0;
    for (i=0; i<NumAssignments; i++)
      assignment[i] = 0;
  }
 
  // Destructor
  OverlappingTemplateMatchingsTest::~OverlappingTemplateMatchingsTest() {
    int i;
 
    windowLength = 0; 
    substringLength = 0;
    substringNumber = 0;
    chiSquared = 0.0;
    eta = 0.0;
    lambda = 0.0;
    for (i=0; i<NumAssignments; i++)
      assignment[i] = 0;
  }
  
  // Tests the BaseCryptoRandomStream executed and returns the random value
  bool OverlappingTemplateMatchingsTest::IsRandom(BaseCryptoRandomStream* bitStream) {
    int    i, k, match;
    double W_obs, sum;
    int    j, K = 5;
    unsigned int nu[6] = {0,0,0,0,0,0};
    double pi[6] = {0.143783,0.139430,0.137319,0.124314,0.106209,0.348945};
    bitItem*   patern;      
 
    if ((bitStream->GetBitLength() < this->GetMinimumLength())) {
      this->error = InsufficientNumberOfBits;
      this->random = false;
      return this->random; 
    }
    this->error = NoError;
    this->substringLength = OverlappingStringTested;
    this->substringNumber = (int)floor((long double)(bitStream->GetBitLength()/this->substringLength));
    if ((patern = (bitItem*) calloc(this->windowLength,sizeof(bitItem))) == NULL) {
      this->error = InsufficientMemory;
      this->random = false;
      return this->random; 
    }
    else
      for(i = 0; i < this->windowLength; i++)
        patern[i].bit = 1;
    this->lambda = (double)(this->substringLength-this->windowLength+1)/pow((double)2,this->windowLength);
    this->eta = this->lambda/2.0;
    sum = 0.0;
    for(i = 0; i < K; i++) {      
      pi[i] = Probability(i,this->eta);
      sum += pi[i];
    }
    pi[K] = 1 - sum;
    for(i = 0; i < this->substringNumber; i++) {
      W_obs = 0;
      for(j = 0; j < this->substringLength-this->windowLength+1; j++) {
        match = 1;
        for(k = 0; k < this->windowLength; k++) {
          if ((int)patern[k] != (int)bitStream->GetBitPosition(i*this->substringLength+j+k))
            match = 0;
        }
        if (match == 1)
          W_obs++;
      }
      if (W_obs <= 4)
        nu[(int)W_obs]++;
      else
        nu[K]++;
    }  
    sum = 0;
    this->chiSquared = 0.0;                              
    for(i = 0; i < K+1; i++) {
      this->chiSquared += pow((double)nu[i]-(double)this->substringNumber*pi[i],2)/((double)this->substringNumber*pi[i]);
        sum += nu[i];
    }
    this->pValue = this->mathFuncs->IGammaC(K/2.,this->chiSquared/2.);
    for (i = 0; i < 6; i++)
      this->assignment[i] = nu[i];
    if (_isnan(this->pValue)) {
      this->pValue = 0;
      this->error = MathematicianNAN;
      this->random = false;
    }
    else {
      if (isNegative(this->pValue) || isGreaterThanOne(this->pValue)) {
           this->error = PValueOutOfRange;
        this->random = false;
      }
      else {
        if (this->pValue < this->alpha) {     
          this->error = NoError;
          this->random = false;
        }
        else {
          this->error = NoError;
          this->random = true;
        }
      }
    }
    free(patern);
    return this->random;
  }
 
  // Initializes the object
  void OverlappingTemplateMatchingsTest::Initialize(void) {
    int i;
 
    BaseRandomTest::Initialize();
    windowLength = 0; 
    substringLength = 0;
    substringNumber = 0;
    chiSquared = 0.0;
    eta = 0.0;
    lambda = 0.0;
    for (i=0; i<NumAssignments; i++)
      assignment[i] = 0;
  }
 
  // Gets the type of the object
  RandomTests OverlappingTemplateMatchingsTest::GetType(void) {
 
    return this->test;
  }
 
  // Gets the minimum random stream length
  unsigned int OverlappingTemplateMatchingsTest::GetMinimumLength(void) {
 
    return this->minimumLength;
  }
 
  // Gets an array of block sizes
  int OverlappingTemplateMatchingsTest::GetWindowLengths(void) {
 
    return this->numberWindowLengths;
  }
 
  // Gets the window length based on the index
  int OverlappingTemplateMatchingsTest::GetWindowLengthOfIndex(int index) {
 
    return this->windowLengths[index];
  }
 
  // Sets the "WindowLength" parameter
  void OverlappingTemplateMatchingsTest::SetWindowLength(int window) {
 
    this->windowLength = window;
  }
 
  // Gets the "WindowLength" parameter
  int OverlappingTemplateMatchingsTest::GetWindowLength(void) {
 
    return this->windowLength;
  }
 
  // Gets the "substringLength" result
  int OverlappingTemplateMatchingsTest::GetSubstringLength(void) {
 
    return this->substringLength;
  }
 
  // Gets the "substringNumber" result
  int OverlappingTemplateMatchingsTest::GetSubstringNumber(void) {
 
    return this->substringNumber;
  }
 
  // Gets the "chiSquared" result
  double OverlappingTemplateMatchingsTest::GetChiSquared(void) {
 
    return this->chiSquared;
  }
 
  // Gets the "eta" result
  double OverlappingTemplateMatchingsTest::GetEta(void) {
 
    return this->eta;
  }
 
  // Gets the "lambda" result
  double OverlappingTemplateMatchingsTest::GetLambda(void) {
 
    return this->lambda;
  }
 
  // Gets the Assignment result
  void OverlappingTemplateMatchingsTest::GetAssignment(unsigned int *assign) {
 
    memcpy (assign, assignment, sizeof(unsigned int)*NumAssignments);
  }
 
  // Gets the Assignment result based on the index
  unsigned int OverlappingTemplateMatchingsTest::GetAssignmentOfIndex(int index) {
 
    return this->assignment[index];
  }
 
  // Computes probability
  double OverlappingTemplateMatchingsTest::Probability(int u, double eta) {
    int    l;
    double sum, p;
 
    if (u == 0)
      p = exp(-eta);
    else {
      sum = 0.0;
      for(l = 1; l <= u; l++)
        sum += exp(-eta-u*log((double)2)+l*log((long double)eta)-this->mathFuncs->LGamma(l+1) 
             + this->mathFuncs->LGamma(u) - this->mathFuncs->LGamma(l)- this->mathFuncs->LGamma(u-l+1));
      p = sum;
    }
    return p;
  }
  }
}
 
 
 



Close Me  
Get FREE Random Number Test Windows DLL !
Get FREE Hash Algorithms Windows DLL !