Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <math.h>
- int main (int argc, char **argv) {
- int rfd, i, out_size;
- out_size = 64;
- char random_output[out_size];
- rfd = open("/dev/urandom", O_RDONLY);
- if (rfd < 0) {
- fprintf(stderr, "Could not open /dev/urandom: %m\n");
- goto endofrandom;
- }
- if (read(rfd, random_output, out_size) < 0) {
- fprintf(stderr, "Could not read from /dev/urandom. %m\n");
- goto endofrandom;
- }
- if (argc == 2) {
- if ( !strcmp(argv[1], "-hex") || !strcmp(argv[1], "--hex") ) {
- for ( i = 0; i <= out_size; ++i ) {
- printf("\\x%X", abs(*(random_output +i)));
- }
- } else if ( !strcmp(argv[1], "-dec") || !strcmp(argv[1], "--dec") ) {
- for ( i = 0; i <= out_size; ++i ) {
- printf("\\%d", abs(*(random_output +i)));
- }
- } else if ( !strcmp(argv[1], "-oct") || !strcmp(argv[1], "--oct") ) {
- printf("Future feature\n");
- }
- printf("%c", 10);
- } else {
- printf("Usage: %s: -hex|-dec|-oct\n");
- }
- endofrandom:
- close(rfd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment