Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- // Need this to remove warnings while using MD5
- #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
- #include "rng.h"
- #include "md5.h"
- using namespace std;
- using namespace CryptoPP;
- int main( int argc, char** argv )
- {
- if( argc < 2 )
- {
- cout << "Usage: ./program [iterations]";
- return 0;
- }
- int runs = atoi( argv[1] );
- MaurerRandomnessTest mt;
- Weak::MD5 md5;
- byte* digest = new byte[16];
- byte* message = new byte[4];
- stringstream first, middle, last;
- for( int i = 0; i < runs; ++i )
- {
- // Convert integer to byte array.
- for( int j = 0; j < 4; ++j )
- message[j] = (byte) ( ( i >> ( j * 8 ) ) & 0x000000FF );
- // Feed MD5 with our message (iteration count) and receive our digest.
- md5.Update( message, 4 );
- md5.Final( digest );
- // Split the digest into three portions. 8 Bytes samples from the beginning,
- // the middle, and the end, respectively.
- for( int j = 0; j <= 7; j++ )
- first << digest[j];
- for( int j = 4; j <= 11; j++ )
- middle << digest[j];
- for( int j = 8; j <= 15; j++ )
- last << digest[j];
- }
- StringStore str( first.str() );
- str.TransferAllTo( mt );
- cout << "First: ";
- if( mt.BytesNeeded() > 0 )
- cout << "Not enough data.";
- else
- cout << mt.GetTestValue();
- cout << endl;
- str = StringStore( middle.str() );
- str.TransferAllTo( mt );
- cout << "Middle: ";
- if( mt.BytesNeeded() > 0 )
- cout << "Not enough data.";
- else
- cout << mt.GetTestValue();
- cout << endl;
- str = StringStore( last.str() );
- str.TransferAllTo( mt );
- cout << "Last: ";
- if( mt.BytesNeeded() > 0 )
- cout << "Not enough data.";
- else
- cout << mt.GetTestValue();
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement