forked from sbshrey/DiPETrans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
66 lines (58 loc) · 1.16 KB
/
utils.cpp
File metadata and controls
66 lines (58 loc) · 1.16 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
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include "utils.h"
#include <openssl/sha.h>
#include <sstream>
#include <iomanip>
using namespace std;
string sha256(const string str) {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(hash, &sha256);
//cout << "hash" << hash << endl;
stringstream ss;
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
ss << hex << setw(2) << setfill('0') << (int)hash[i];
}
return ss.str();
}
double hexTodouble(const std::string& hexstr)
{
long l;
//double d;
stringstream ss;
ss << hex << hexstr;
ss >> l;
return (double)l;
}
int8_t hexToint8(const std::string& hexstr)
{
long l;
//double d;
stringstream ss;
ss << hex << hexstr;
ss >> l;
return (int8_t)l;
}
int32_t hexToint32(const std::string& hexstr)
{
long l;
//double d;
stringstream ss;
ss << hex << hexstr;
ss >> l;
return (int32_t)l;
}
int64_t hexToint64(const std::string& hexstr)
{
long l;
//double d;
stringstream ss;
ss << hex << hexstr;
ss >> l;
return (int64_t)l;
}