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

Compute Discrete Fourier Transform random number test with DiscreteFourierTransformTest Class 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
In these lines we are going to show how to set up Microsoft Visual C++ 2008 Professional to use DiscreteFourierTransformTest class implemented in DiceLockSecurity namespace to compute Discrete Fourier Transform test on random number bit streams with DiceChecker FREE product.

In this page we are going to show the steps to use DiscreteFourierTransformTest Class in a simple application, it does not show all DiscreteFourierTransformTest class capabilities. If you want a deeper knowledge of the class you can get DiceCheck Random Test Source Code 2.0.0.1

This article is structured in three concepts:
- Project Creation
- Project Properties
- Execution


Project Creation

Create the project

In Microsoft Visual C++ 2008 Professional select File, New, Project..., select Project type Visual C++ CLR Console Application call it UsingDiceChecker for example like in:


Add test file

Select Solution, right click and select Open Folder in Windows Explorer, copy random number test data.e file (the file can be found in DiceCheck product) in the folder like in:


You can insert the file in the project explorer with the folder Resource Files, Add, Existing Item..., and selecting the file. Solution Explorer will look like:

data-e.jpg

Insert Source Code

Edit stdafx.h file and insert the following C++ code:

 

// stdafx.h : include file for standard system include files,

// or project specific include files that are used frequently, but

// are changed infrequently

//

 

#pragma once

 

// TODO: reference additional headers your program requires here

#include "diceChecker.h"

 

Edit UsingDiceChecker.cpp file and insert the following C++ code where a DiscreteFourierTransformTest object is instantiated and used to compute Discrete Fourier Transform test with random number test data supplied in data.e file:

 

// UsingDiceChecker.cpp : main project file.

 

#include "stdafx.h"

 

using namespace System;  

using namespace DiceLockSecurity;

using namespace DiceLockSecurity::RandomTest; 

using namespace System;

using namespace System::IO; 

 

void readASCIIFile(String ^file, unsigned int  streamLength, DefaultCryptoRandomStream* stream) {

    unsigned char character;

 

   try { stream->SetBitPosition(0);

      //Pass the file path and file name to the StreamReader constructor.

      StreamReader^ sr = gcnew StreamReader(file);

      //Read the first line of text.

      while ((!sr->EndOfStream) && (stream->GetBitPosition() < streamLength)) {

                  character = sr->Read();

         if (character == '0') stream->SetBitForward(0);

         if (character == '1') stream->SetBitForward(1);

      }

            sr->Close();

    }

    catch (char* str) {

      throw str;

    }

}

 

int main(array<System::String ^> ^args)

{

    String^ fileData;

    DefaultCryptoRandomStream* stream;

    DiscreteFourierTransformTest* discreteFourierTransformTest;

    bool random;

    fileData = gcnew String("");

 

    Console::WriteLine(L""); 

    fileData = System::IO::Directory::GetCurrentDirectory() + "\\data.e";

    stream = new DefaultCryptoRandomStream(1000000);

    readASCIIFile(fileData, 1000000, stream);

    discreteFourierTransformTest = new DiscreteFourierTransformTest();

    discreteFourierTransformTest->SetAlpha(0.05);

    random = discreteFourierTransformTest->IsRandom(stream);

    Console::WriteLine(" NIST        p-value: 0,443864");

    Console::WriteLine(" DiceChecker p-value: {0}", discreteFourierTransformTest->GetPValue().ToString("0.000000")); 

    delete discreteFourierTransformTest;

    delete stream; 

    return 0;

}
 

DiceChecker DLL


Copy DiceChecker.dll dynamic link library file where the Project will create the executable, in our case is under Release folder like in:


Project Properties

General

These are the general properties of the application:


C++ General

Select Additional Include Directories, to allow the application to find diceChecker.h header file. On our case it is located at "C:\Program Files\DiceLock Security\DiceChecker\include" directory:


C++ Compiler Command Line

The compiler command line will look like this:


The compiler command line options are:

 
/GL /I "C:\Program Files\DiceLock Security\DiceChecker\include" /D "WIN32" /D "NDEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MD /Yu"stdafx.h" /Fp"Release\UsingDiceChecker.pch" /Fo"Release\\" /Fd"Release\vc90.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
 

Linker General

In the Linker General Section add the directory where DiceChecker.lib is located in the Additional Library Directories option. In our case the directory is "C:\Program Files\DiceLock Security\DiceChecker\lib".


Linker Input

Once the previous options have been included, go to Linker Input Section and insert in Additional Dependencies the proper library, DiceChecker.lib.


Linker Command Line

The linker command line will look like this:


The linker command line options are:

 
/OUT:"C:\Users\Administrador\Desktop\Projects\DifferentTests\UsingDiceChecker\Release\UsingDiceChecker.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files\DiceLock Security\DiceChecker\lib" /MANIFEST /MANIFESTFILE:"Release\UsingDiceChecker.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"c:\Users\Administrador\Desktop\Projects\DifferentTests\UsingDiceChecker\Release\UsingDiceChecker.pdb" /LTCG /DYNAMICBASE /FIXED:No /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT DiceChecker.lib
 


Execution

Once all previous steps have been completed, select Debug option, Start Without Debugging, and the application will be compiled, linked and executed.

The command line application executed will look like the following screenshot where you will be able to verify that DiscreteFourierTransformTest class performs as expected.

 



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