-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomHasher.cpp
More file actions
57 lines (46 loc) · 1.42 KB
/
Copy pathrandomHasher.cpp
File metadata and controls
57 lines (46 loc) · 1.42 KB
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
#include <iostream>
#include <string>
#include <stdlib.h>
#include <sha.h>
#include <hex.h>
#include <filters.h>
#include <cryptlib.h>
//#pragma comment(lib, "cryptlib.lib") // Adicione esta linha para garantir que o linker use a biblioteca correta
using namespace std;
using namespace CryptoPP;
void GenerateSHA256Hash(const string& input, string& output) {
// Definindo o objeto SHA256
SHA256 hash;
// Definindo o objeto StringSource
StringSource(input, true,
new HashFilter(hash,
new HexEncoder(
new StringSink(output)
) // HexEncoder
) // HashFilter
); // StringSource
}
string RandomString(int lenght)
{
string charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
// string charset = "0123456789abcdefghijklmnopqrstuvwxyz";
string rstring;
int pos;
while (rstring.size() != lenght) {
pos = ((rand() % (charset.size() - 1)));
rstring += charset.substr(pos, 1);
}
return rstring;
}
int main() {
srand(time(0));
int randomStringSize;
cout << "insira o tamanho da string: ";
cin >> randomStringSize;
string randomStringOut = RandomString(randomStringSize);
string SHA256_out;
GenerateSHA256Hash(randomStringOut, SHA256_out);
cout << endl << "Hash SHA-256: " << SHA256_out << endl;
cout << endl << "string original: " << randomStringOut;
return 0;
}