-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample.cpp
More file actions
84 lines (70 loc) · 1.31 KB
/
sample.cpp
File metadata and controls
84 lines (70 loc) · 1.31 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <string.h>
#include <string>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <openssl/sha.h>
void calSHA256(char* inp,char out_buff[65]){
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, inp, strlen(inp));
SHA256_Final(hash, &sha256);
//char buffx[65];
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
sprintf(out_buff + (i * 2), "%02x", hash[i]);
}
out_buff[65] = 0;
//memcpy(out_buff,buffx,65);
}
void itos(int n,char *buffer){
int i = 0;
bool isNeg = n<0;
unsigned int n1 = isNeg ? -n : n;
while(n1!=0)
{
buffer[i++] = n1%10+'0';
n1=n1/10;
}
if(isNeg)
buffer[i++] = '-';
buffer[i] = '\0';
for(int t = 0; t < i/2; t++)
{
buffer[t] ^= buffer[i-t-1];
buffer[i-t-1] ^= buffer[t];
buffer[t] ^= buffer[i-t-1];
}
if(n == 0)
{
buffer[0] = '0';
buffer[1] = '\0';
}
}
long stoi(const char *s)
{
long i;
i = 0;
while(*s >= '0' && *s <= '9')
{
i = i * 10 + (*s - '0');
s++;
}
return i;
}
using namespace std;
int main(int argc,char** argv){
if(argc < 2)
return 1;
int c = stoi(argv[1]);
if(c<0)
return 1;
printf("%d\n",c);
char buff[65];
for(int i=0;i<c;i++){
itos(i,buff);
calSHA256(buff,buff);
printf("%s\n",buff);
}
}