arg handle
This commit is contained in:
parent
42d5b1fea8
commit
e566be4122
1 changed files with 68 additions and 6 deletions
|
|
@ -21,6 +21,72 @@ void invalid_args(int argc) {
|
|||
}
|
||||
}
|
||||
|
||||
char* character_list(int argc, char** argv) {
|
||||
const char uppercase[] = "QWERTZUIOPASDFGHJKLYXCVBNM";
|
||||
const char lowercase[] = "qwertzuiopasdfghjklyxcvbnm";
|
||||
const char symbols[] = "/!?._-#&";
|
||||
const char numbers[] = "0123456789";
|
||||
|
||||
char* output;
|
||||
|
||||
if (argc == 4) {
|
||||
int final_size = 0;
|
||||
|
||||
for (int i = 0; argv[3][i] != '\0'; i++) {
|
||||
switch (argv[3][i]) {
|
||||
case 'U':
|
||||
final_size += sizeof(uppercase) - 1;
|
||||
break;
|
||||
case 'L':
|
||||
final_size += sizeof(lowercase) - 1;
|
||||
break;
|
||||
case 's':
|
||||
final_size += sizeof(symbols) - 1;
|
||||
break;
|
||||
case 'n':
|
||||
final_size += sizeof(numbers) - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
output = malloc(sizeof(char) * (final_size + 1));
|
||||
|
||||
int copy_index = 0;
|
||||
|
||||
for (int i = 0; argv[3][i] != '\0'; i++) {
|
||||
const char* current_list;
|
||||
int size;
|
||||
|
||||
switch (argv[3][i]) {
|
||||
case 'U':
|
||||
current_list = uppercase;
|
||||
size = sizeof(uppercase);
|
||||
break;
|
||||
case 'L':
|
||||
current_list = lowercase;
|
||||
size = sizeof(lowercase);
|
||||
break;
|
||||
case 's':
|
||||
current_list = symbols;
|
||||
size = sizeof(symbols);
|
||||
break;
|
||||
case 'n':
|
||||
current_list = numbers;
|
||||
size = sizeof(numbers);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int j = 0; j < size - 1; j++) {
|
||||
output[copy_index] = current_list[j];
|
||||
copy_index++;
|
||||
}
|
||||
|
||||
output[final_size] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
int random_len(int min_length, int max_length) {
|
||||
return rand() % (max_length - min_length + 1) + min_length;
|
||||
}
|
||||
|
|
@ -47,12 +113,8 @@ int main(int argc, char** argv) {
|
|||
|
||||
int length = random_len(min_length, max_length);
|
||||
|
||||
if (argc != 4) {
|
||||
char* password = random_str(length, argv[4]);
|
||||
puts(password);
|
||||
free(password);
|
||||
} else {
|
||||
char* password = random_str(length, argv[3]);
|
||||
if (argc == 4) {
|
||||
char* password = random_str(length, character_list(argc, argv));
|
||||
puts(password);
|
||||
free(password);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue