initial commit <3
This commit is contained in:
44
main.c
Normal file
44
main.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "limits.h"
|
||||
#include "sodium.h"
|
||||
#include "strtoui.h"
|
||||
|
||||
int map(int i, int i_min, int i_max, int o_min, int o_max) {
|
||||
double r = (double)(o_max - o_min) / (double)(i_max - i_min);
|
||||
int j = (double) (i - i_min) * r + o_min;
|
||||
return j;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc == 1) {
|
||||
puts("Usage: chars [length]");
|
||||
puts(" Max length is 1024");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
unsigned int len;
|
||||
enum strtoui_error error = strtoui(&len, argv[1], 10);
|
||||
if(error != STRTOUI_SUCCESS){
|
||||
fputs("Bad input\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}else if (len > 1024) {
|
||||
fputs("The length is to big\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char lower_range = 0x20;
|
||||
char upper_range= 0x7e;
|
||||
|
||||
char data[len];
|
||||
randombytes_buf(data, sizeof len);
|
||||
|
||||
for(int i = 0; i < len; i++) {
|
||||
int random = randombytes_uniform(upper_range);
|
||||
data[i] = map(random, 0, upper_range, lower_range, upper_range);
|
||||
printf("%c", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
Reference in New Issue
Block a user