Jump to content

Kb's Generator Of Passwords


Kamikaze_Badger

Recommended Posts

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int i;
int j;
int* k;
int l;

char numbers1[10];
char numbers2[10];
char numbers3[10];
char numbers4[10];
char numbers5[10];
char numbers6[10];
char numbers7[10];
char numbers8[10];
char numbers9[10];
char numbers10[10];

char temp;

char characterArray[78] = 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '`' '~' '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '-' '_' '=' '+' '\\' '/' '\'' '\"\' '.' ',';

j = sizeof(characterArray);

int main(void) {
   
   srand(time(NULL)); /*Seed the rand() function*/
   
   for(i = 0;i<10;i++) { /*Loop for inserting numbers*/
       numbers1[i] = rand % 9;
       numbers2[i] = rand % 9;
       numbers3[i] = rand % 9;
       numbers4[i] = rand % 9;
       numbers5[i] = rand % 9;
       numbers6[i] = rand % 9;
       numbers7[i] = rand % 9;
       numbers8[i] = rand % 9;
       numbers9[i] = rand % 9;
       numbers10[i] = rand % 9;
       
   }
   
   for(i = 0;i<10;i++) { /*Loop for inserting characters*/
       l = rand() % j;
       k = &characterArray[l];
       
       numbers1[l] = *k;
       numbers2[l] = *k;
       numbers3[l] = *k;
       numbers4[l] = *k;
       numbers5[l] = *k;
       numbers6[l] = *k;
       numbers7[l] = *k;
       numbers8[l] = *k;
       numbers9[l] = *k;
       numbers10[l] = *k;
       
   }
   
   printf("Generated passwords:\n\n %n\%n\%n\%n\%n%n\%n\%n\%n\%n\n\n", numbers1, numbers 2, numbers3, numbers4, numbers5, numbers6, numbers7, numbers8, numbers9, numbers10);
   
   system("pause");
   
   return 0;
   
}    

 

Well, where did I screw up now?

Share this post


Link to post
Share on other sites

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int i;
int j;
int* k;
int l;

char numbers1[10];
char numbers2[10];
char numbers3[10];
char numbers4[10];
char numbers5[10];
char numbers6[10];
char numbers7[10];
char numbers8[10];
char numbers9[10];
char numbers10[10];

char temp;

char characterArray[78] = 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '`' '~' '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '-' '_' '=' '+' '\\' '/' '\'' '\"\' '.' ',';

j = sizeof(characterArray);

int main(void) {
   
   srand(time(NULL)); /*Seed the rand() function*/
   
   for(i = 0;i<10;i++) { /*Loop for inserting numbers*/
       numbers1[i] = rand % 9;
       numbers2[i] = rand % 9;
       numbers3[i] = rand % 9;
       numbers4[i] = rand % 9;
       numbers5[i] = rand % 9;
       numbers6[i] = rand % 9;
       numbers7[i] = rand % 9;
       numbers8[i] = rand % 9;
       numbers9[i] = rand % 9;
       numbers10[i] = rand % 9;
       
   }
   
   for(i = 0;i<10;i++) { /*Loop for inserting characters*/
       l = rand() % j;
       k = &characterArray[l];
       
       numbers1[l] = *k;
       numbers2[l] = *k;
       numbers3[l] = *k;
       numbers4[l] = *k;
       numbers5[l] = *k;
       numbers6[l] = *k;
       numbers7[l] = *k;
       numbers8[l] = *k;
       numbers9[l] = *k;
       numbers10[l] = *k;
       
   }
   
   printf("Generated passwords:\n\n %n\%n\%n\%n\%n%n\%n\%n\%n\%n\n\n", numbers1, numbers 2, numbers3, numbers4, numbers5, numbers6, numbers7, numbers8, numbers9, numbers10);
   
   system("pause");
   
   return 0;
   
}    

 

Well, where did I screw up now?

595141[/snapback]

 

I will have to get back to you at the weekend I am afraid, if no one answers before that. I'm overly busy with two bits of Uni coursework which, well, are really quite big and.... I only have a few days to finish them! Sorry!

 

For what it's worth I can tell you from like... a 10 second look that you probably want something more like:

 

printf("Generated passwords:\n\n %d\n %d\n", numbers1, numbers2);

Share this post


Link to post
Share on other sites

After some improvements then...

 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int i;
/*int j;*/
char* k;
int l;

char numbers1[10];
char numbers2[10];
char numbers3[10];
char numbers4[10];
char numbers5[10];
char numbers6[10];
char numbers7[10];
char numbers8[10];
char numbers9[10];
char numbers10[10];

char characterArray[78] = 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '`' '~' '!' '@' '#' '$' '%' '^' '&' '*';

int j = sizeof(characterArray);

int main(void) {
   
   srand(time(NULL)); /*Seed the rand() function*/
   
   for(i = 0;i<10;i++) { /*Loop for inserting numbers*/
       numbers1[i] = rand % 9;
       numbers2[i] = rand % 9;
       numbers3[i] = rand % 9;
       numbers4[i] = rand % 9;
       numbers5[i] = rand % 9;
       numbers6[i] = rand % 9;
       numbers7[i] = rand % 9;
       numbers8[i] = rand % 9;
       numbers9[i] = rand % 9;
       numbers10[i] = rand % 9;
       
   }
   
   for(i = 0;i<10;i++) { /*Loop for inserting characters*/
       l = rand() % j;
       k = &characterArray[l];
       
       numbers1[l] = *k;
       numbers2[l] = *k;
       numbers3[l] = *k;
       numbers4[l] = *k;
       numbers5[l] = *k;
       numbers6[l] = *k;
       numbers7[l] = *k;
       numbers8[l] = *k;
       numbers9[l] = *k;
       numbers10[l] = *k;
       
   }
   
   printf("Generated passwords:\n\n %d\%d\%d\%d\%d\%d\%d\%d\%d\%d\%d", numbers1[], numbers 2[], numbers3[], numbers4[], numbers5[], numbers6[], numbers7[], numbers8[], numbers9[], numbers10[]);
   
   system("pause");
   
   return 0;
   
}

Share this post


Link to post
Share on other sites

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

/*
  Variables
*/
int i, l;
char* k;

char numbers1[10];
char numbers2[10];
char numbers3[10];
char numbers4[10];
char numbers5[10];
char numbers6[10];
char numbers7[10];
char numbers8[10];
char numbers9[10];
char numbers10[10];

char characterArray[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*'};
int j = sizeof(characterArray);

/*
  Prototypes
*/
void InsertRandomCharacter(char *, int);

/*
  Functions
*/
void InsertRandomCharacter(char *ar, int slot) {
   l = rand() % j;
   k = &characterArray[l];

   ar[slot] = *k;
}

int main(void) {
  srand(time(NULL)); /*Seed the rand() function*/

  for (i = 0; i < 10; i++) { /*Loop for inserting numbers*/
      numbers1[i] = rand() % 9;
      numbers2[i] = rand() % 9;
      numbers3[i] = rand() % 9;
      numbers4[i] = rand() % 9;
      numbers5[i] = rand() % 9;
      numbers6[i] = rand() % 9;
      numbers7[i] = rand() % 9;
      numbers8[i] = rand() % 9;
      numbers9[i] = rand() % 9;
      numbers10[i] = rand() % 9;

  }

  for (i = 0; i < 10; i++) { /*Loop for inserting characters*/
       InsertRandomCharacter(numbers1, i);
       InsertRandomCharacter(numbers2, i);
       InsertRandomCharacter(numbers3, i);
       InsertRandomCharacter(numbers4, i);
       InsertRandomCharacter(numbers5, i);
       InsertRandomCharacter(numbers6, i);
       InsertRandomCharacter(numbers7, i);
       InsertRandomCharacter(numbers8, i);
       InsertRandomCharacter(numbers9, i);
       InsertRandomCharacter(numbers10, i);
  }

   printf("Generated Passwords:\n\n");
   for (i = 0; i < 10; i++) {
       printf("%d. %c%c%c%c%c%c%c%c%c%c%c\n", i, numbers1[i], numbers2[i], numbers3[i], numbers4[i], numbers5[i], numbers6[i], numbers7[i], numbers8[i], numbers9[i], numbers10[i]);
   }

  system("pause");

  return 0;

}

 

Thar you go!

 

........

 

Back to work :(

Share this post


Link to post
Share on other sites

The only issues as far as I can remember were:

 

char characterArray[78] = 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '`' '~' '!' '@' '#' '$' '%' '^' '&' '*';

 

There's not 78 items there, use [] and it'll automatically create the right size array.

 

No comma's between each element ('A', 'B' .... 'Z') and no starting { and ending } ( char something[] = {'a', 'b'}; )

 

       numbers1[i] = rand % 9;
      numbers2[i] = rand % 9;
      numbers3[i] = rand % 9;
      numbers4[i] = rand % 9;
      numbers5[i] = rand % 9;
      numbers6[i] = rand % 9;
      numbers7[i] = rand % 9;
      numbers8[i] = rand % 9;
      numbers9[i] = rand % 9;
      numbers10[i] = rand % 9;

 

Forgot the () at the end of the rand's

 

       l = rand() % j;
      k = &characterArray[l];
      
      numbers1[l] = *k;
      numbers2[l] = *k;
      numbers3[l] = *k;
      numbers4[l] = *k;
      numbers5[l] = *k;
      numbers6[l] = *k;
      numbers7[l] = *k;
      numbers8[l] = *k;
      numbers9[l] = *k;
      numbers10[l] = *k;

 

Would have been ok, but k is going to be the same random character all the time, so all 10 passwords would be identical :)

 

  printf("Generated passwords:\n\n %d\%d\%d\%d\%d\%d\%d\%d\%d\%d\%d", numbers1[], numbers 2[], numbers3[], numbers4[], numbers5[], numbers6[], numbers7[], numbers8[], numbers9[], numbers10[]);

 

This was partly my fault. I assume you were printing numbers when I saw the variable names (numbersX). You're actually printing characters in a character array, so %d needs to be %c.

 

There would also need to be a loop around the printf to print each character in the number arrays. The way I did it the passwords are actually created from a mix of all the number arrays. Figured it didn't matter much because you want random passwords :) You could have null terminated each of the number arrays (not actually that hard to do), used %s instead of %c, and printed them out without the loop.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...