| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | #include <mLib/alloc.h> |
| 6 | #include <mLib/base64.h> |
| 7 | #include <mLib/dstr.h> |
| 8 | #include <mLib/quis.h> |
| 9 | #include <mLib/report.h> |
| 10 | |
| 11 | #include <catacomb/rand.h> |
| 12 | #include <catacomb/noise.h> |
| 13 | |
| 14 | int main(int argc, char *argv[]) |
| 15 | { |
| 16 | dstr d = DSTR_INIT; |
| 17 | base64_ctx b; |
| 18 | char *p; |
| 19 | size_t n; |
| 20 | |
| 21 | ego(argv[0]); |
| 22 | if (argc > 2) { |
| 23 | pquis(stderr, "Usage: $ [BITS]\n"); |
| 24 | exit(EXIT_FAILURE); |
| 25 | } |
| 26 | n = argc == 2 ? atoi(argv[1]) : 128; |
| 27 | if (!n || n % 8) die(EXIT_FAILURE, "bad bit count"); |
| 28 | n >>= 3; |
| 29 | p = xmalloc(n); |
| 30 | rand_noisesrc(RAND_GLOBAL, &noise_source); |
| 31 | rand_seed(RAND_GLOBAL, 160); |
| 32 | rand_get(RAND_GLOBAL, p, n); |
| 33 | base64_init(&b); |
| 34 | b.maxline = 0; |
| 35 | b.indent = ""; |
| 36 | base64_encode(&b, p, n, &d); |
| 37 | base64_encode(&b, 0, 0, &d); |
| 38 | printf("%s\n", d.buf); |
| 39 | return (0); |
| 40 | } |