-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomBytesGenerator.cpp
More file actions
44 lines (37 loc) · 998 Bytes
/
randomBytesGenerator.cpp
File metadata and controls
44 lines (37 loc) · 998 Bytes
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
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <random>
using rng = std::independent_bits_engine<std::mt19937, 8U, uint8_t>;
struct ByteBuffer {
uint8_t BufferSize;
uint8_t ByteBuffer[64];
};
int main(int argc, char *argv[]) {
if (argc < 2) {
std::printf("Usage: %s <len>\n", argv[0]);
return 1;
}
struct ByteBuffer bb;
int len = atoi(argv[1]);
if (len < 65) {
bb.BufferSize = static_cast<uint8_t>(len);
} else {
std::printf("Error: len %d given too big!!\n\tMax len allowed %hhu", len,
64);
return 2;
}
std::printf("recvd len: %d\n", len);
if (bb.BufferSize < 65U) {
rng gen;
gen.seed(std::time(nullptr));
std::generate(bb.ByteBuffer, bb.ByteBuffer + bb.BufferSize, gen);
for (uint8_t i = 0; i < bb.BufferSize; i++) {
std::printf("i: %2hhu | %2hhx \n", i + 1, *(bb.ByteBuffer + i));
}
} else {
std::printf("Error: invalid length not storing");
}
return 0;
}