|
#include "stdafx.h"
#include "profiler.h"
#include "files.h" // FileSource
#include "channels.h" // ChannelSwitch
#include "filters.h" // HashFilter
#include "hex.h" // HexEncoder/HexDecoder
#include "md5.h" // MD5
#include "sha.h" // SHA-1, SHA-224, SHA-256
#include "ripemd.h" // RIPEMD-160
using namespace CryptoPP;
int main(int argc, char* argv[])
{
// string s( 987 * 1024 , ' '); // Create a blanks.
string s = "Benjamin Franklin said, They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.";
MD5 hashMD5;
HashFilter filterMD5(hashMD5);
SHA1 hashSHA1;
HashFilter filterSHA1(hashSHA1);
RIPEMD160 hashRIPEMD160;
HashFilter filterRIPEMD160(hashRIPEMD160);
SHA224 hashSHA224;
HashFilter filterSHA224(hashSHA224);
SHA256 hashSHA256;
HashFilter filterSHA256(hashSHA256);
std::auto_ptr<ChannelSwitch> channelSwitch(new ChannelSwitch);
channelSwitch->AddDefaultRoute(filterMD5);
channelSwitch->AddDefaultRoute(filterSHA1);
channelSwitch->AddDefaultRoute(filterRIPEMD160);
channelSwitch->AddDefaultRoute(filterSHA224);
channelSwitch->AddDefaultRoute(filterSHA256);
{
CProfiler profiler;
__int64 ptime;
profiler.ProfileStart( );
// Crypto++ 5.2.1 source file is 987 kB
// FileSource( "c:\\cryptopp521.zip", true, channelSwitch.release());
StringSource( s /* 987Kb */, true, channelSwitch.release());
// StringSource( "abcdefghijklmnopqrstuvwxyz", true, channelSwitch.release());
ptime = profiler.ProfileEnd();
_tcout << _T("Channel Pump Time: ");
_tcout << profiler.SecsFromTicks( ptime );
_tcout << _T(" seconds") << std::endl << endl;
}
std::cout << "String:" << std::endl << s << std::endl << std::endl;
string digest;
HexEncoder encoder( new StringSink( digest ), true /* uppercase */ );
filterMD5.TransferTo( encoder );
cout << filterMD5.AlgorithmName() << ": " << digest << endl;
digest.erase();
filterSHA1.TransferTo( encoder );
cout << filterSHA1.AlgorithmName() << ": " << digest << endl;
digest.erase();
filterRIPEMD160.TransferTo( encoder );
cout << filterRIPEMD160.AlgorithmName() << ": " << digest << endl;
digest.erase();
filterSHA224.TransferTo( encoder );
cout << filterSHA224.AlgorithmName() << ": " << digest << endl;
digest.erase();
filterSHA256.TransferTo( encoder );
cout << filterSHA256.AlgorithmName() << ": " << digest << endl;
digest.erase();
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.