I wrote this RNG in C. It creates a random Output of ASCII characters in the range between 33 - 122. An Output of 100 characters for example, looks like the following:
Q:[X-Nl&G'
1aqvAk<k^@ir@,ZcUIrWT6n0f"fRv+GEsO[r>DFUC)si<3F?an>qS2+Do+j.?R;+3,;yVu.@jpDE9haA
Here is the full Code which compiles flawlessly with gcc on Windows:
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
int checkIfNum(char *c);
int checkIfAlNum(char *c);
int main(int argc, char * argv[]){
clock_t time1 = clock();
FILE * write;
int i = 0;
int length;
int status;
unsigned int j = 0;
if((argc < 2) || argc > 3){
printf("USAGE: keygen FILENAME LENGTH(MAX: 200.000.000)\nPRESS ANY KEY TO EXIT...\n");
getchar();
return -1;
}
status = checkIfAlNum(argv[1]);
if(status == -1){
printf("ERROR: INVALID FILENAME. USE ONLY ALPHANUM CHARACTERS\n");
return -1;
}
status = checkIfNum(argv[2]);
if(status == -1){
printf("ERROR: INVALID KEYLENGTH. MAX: 200.000.000\n");
return -1;
}
length = atoi(argv[2]);
srand(time(NULL));
write = fopen(argv[1], "w+");
if(write == NULL){
printf("ERROR: COULD NOT CREATE FILE.\n");
}
while(i < length){
time1 = clock();
j = ((rand()+time1)%(122-33)+33);
i++;
fputc(j, write);
}
fclose(write);
return 0;
}
int checkIfNum(char *c){
int i = 0;
while(c[i] != '\0'){
if((isdigit(c[i]) == 0) && i > 9){
return -1;
}
i++;
}
return 0;
}
int checkIfAlNum(char *c){
int i = 0;
while((c[i]) != '\0'){
if((isalnum(c[i]) == 0) && i > 30){
return -1;
}
i++;
}
return 0;
}
Can my implementation be considered cryptographically secure?
I will be very grateful for constructive Feedback
Aucun commentaire:
Enregistrer un commentaire