Ticket #24: mytest2.cpp

File mytest2.cpp, 1.2 KB (added by midnightmagic, at 2009-07-03T19:44:59Z)
Line 
1#include <iostream>
2
3#include "cryptlib.h"
4#include "sha.h"
5#include "hex.h"
6#include "filters.h"
7
8USING_NAMESPACE(CryptoPP);
9
10int main() {
11        SHA256 *hash;
12        hash = new SHA256();
13        SHA256 *hash2;
14        hash2 = new SHA256();
15
16        std::string digest="";
17        std::string digest2="";
18        std::string a1, a2, a3;
19        const byte *b1, *b2, *b3;
20        byte b4[1024], b5[1024];
21        a1="aaa";
22        a2="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
23        a3="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
24        b1=(const byte *)a1.c_str();
25        b2=(const byte *)a2.c_str();
26        b3=(const byte *)a3.c_str();
27
28        hash->Update(b1, 3);
29        hash->Update(b2, 125);
30        hash->Final(b4);
31
32        hash2->Update(b3, 128);
33        hash2->Final(b5);
34
35        HexEncoder encoder(NULL, true, 2, "");
36        encoder.Attach(new StringSink(digest));
37        encoder.Put(b4, 32);
38        encoder.MessageEnd();
39
40        std::cout << "STRING: " << a1 << ":" << a2 << "\n";
41        std::cout << "SHA256: " << digest << "\n";
42
43        HexEncoder encoder2(NULL, true, 2, "");
44        encoder2.Attach(new StringSink(digest2));
45        encoder2.Put(b5, 32);
46        encoder2.MessageEnd();
47
48        std::cout << "STRING: " << a3 << "\n";
49        std::cout << "SHA256: " << digest2 << "\n";
50
51}