I hope it's usefull.

This is a discussion on I hope it's usefull. within the C Programming forums, part of the General Programming Boards category; I am new to programming an this is a password file generator i made. I don't know how big it ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    16

    I hope it's usefull.

    I am new to programming an this is a password file generator i made. I don't know how big it is i stopped it at 75GBs.
    Code:
     
     #include <stdio.h>
    
    int main()
    {
      FILE *f;
      char a[95]="abcdefghijklmnopqrstuvwuxyzABCDEFGHIJKLMNOPQRSTUVWXY`Z1234567890-=[];',./~!@#$%^&*()_+{}|:<>?";
      char c;
      int b[8];
    
      f=fopen( "password.txt", "w" );
      printf( "Are you sure you wan't to make this file its almost 20GB?(y/n)\n" );
      printf( ">>" );
      scanf( "%c", &c );
      switch ( c ) {
       case 'y':
        for ( b[1] = 0; b[1] < 95; b[1]++ ) {
         for ( b[2] = 0; b[2] < 95; b[2]++ ) {
          for ( b[3] = 0; b[3] < 95; b[3]++ ) {
           for ( b[4] = 0; b[4] < 95; b[4]++ ) {
            for ( b[5] = 0; b[5] < 95; b[5]++ ) {
             for ( b[6] = 0; b[6] < 95; b[6]++ ) {
              for ( b[7] = 0; b[7] < 95; b[7]++ ) {
               for ( b[0] = 0; b[0] < 95; b[0]++ ) {
                fprintf( f, "%c%c%c%c%c%c%c%c\n", a[b[1]], a[b[2]], a[b[3]], a[b[4]], a[b[5]], a[b[6]], a[b[7]],a[b[0]] );
               }
              }
             }
            }
           }
          }
         }
        }
        break;
       case 'n':
        printf( "Good bye.\n" );
        break;
       default:
        break;
      }
      return 0;
    }
    Last edited by devildog561; 12-12-2011 at 07:34 PM.

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Looks good, but a couple tips..:

    - Indent/returns. No one likes reading one huge strip of code, even if it wasn't your fault.

    - Instead of having a huge lookup table for all of the values, it's easier to pick a random number between 30 ('0') and 122 ('z'), and use that to fill your file. For reference on the numbers that correspond to letters: Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion

    - Make the file-size customizable on all of its dimensions. #defines or interpreting command-line arguments are the best ways to do this.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    16
    Quote Originally Posted by memcpy View Post
    Looks good, but a couple tips..: - Indent/returns. No one likes reading one huge strip of code, even if it wasn't your fault. - Instead of having a huge lookup table for all of the values, it's easier to pick a random number between 30 ('0') and 122 ('z'), and use that to fill your file. For reference on the numbers that correspond to letters: Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion - Make the file-size customizable on all of its dimensions. #defines or interpreting command-line arguments are the best ways to do this.
    The only one i understand is the first one and i fixed that.

  4. #4
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You're generating every eight-character sequence from a 95 symbol character set.

    There will be 95^8 such sequences, each nine characters long (sequence plus newline). Each character is one byte. So the file size will be 9*(95^8)=59,707,838,816,015,625 bytes. That's something like six million gig.

    Don't do it.
    Code:
    while(!asleep) {
       sheep++;
    }

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    16
    Quote Originally Posted by TheBigH View Post
    You're generating every eight-character sequence from a 95 symbol character set. There will be 95^8 such sequences, each nine characters long (sequence plus newline). Each character is one byte. So the file size will be 9*(95^8)=59,707,838,816,015,625 bytes. That's something like six million gig. Don't do it.
    When I did the math before i set it off somehow I came up with 20gigs.

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by devildog561 View Post
    When I did the math before i set it off somehow I came up with 20gigs.
    I don't see the relevance of posting this here, as your math is obviously untrue and whatever explanation you have for it is not necessary.

    Quote Originally Posted by devildog561 View Post
    The only one i understand is the first one and i fixed that.


    I gave you a link for the only part that would be difficult to google. Everything else is easily google-able. For reference:

    - page for #defines: Preprocessor directives - C++ Documentation
    - and I already gave you the link to the ASCII chart, but a quick explanation would be:

    Characters (a,b,c,etc..) are represented in memory by arrays of numbers. Every character has its own number, and as you probably already know, numbers can be iterated through using for loops. A for loop running from 30 to 39, and then with a "printf("%c")", will print out the representations for those numbers, being 0,1,2,3,etc...

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Try it like this... (tested)
    Code:
    // instant passwords
    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    
    int main (void)
      {
        int num, i;
        char pass[16] = {0};
        FILE *f;
       
        srand(time(0));
    
        printf("How many passwords do you need (1 - 1000) : ");
        scanf("%d",&num);    
    
        f = fopen("passwords.txt","w");
        if (!f)
          { 
             printf("Can't open the output file");
             exit(1);
          }
    
        while (num > 0)
          {
             for(i = 0; i < 15; i++)
                pass[i] = (rand() % ('z' - ' ')) + ' ';
             pass[15] = 0;       
             fprintf(f,"%s\n\n",pass);
             num--;
          }
    
       fclose(f); 
       printf("Done\n\n");
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why FD_WRITE is usefull on select()?
    By Andaluz in forum Linux Programming
    Replies: 7
    Last Post: 07-01-2010, 10:02 AM
  2. Is this usefull? {}
    By mikahell in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2006, 03:08 PM
  3. Usefull.h file, ExitWindows, Fullscreen...
    By Yuri in forum C++ Programming
    Replies: 10
    Last Post: 08-15-2005, 07:51 AM
  4. Usefull Library
    By Thantos in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-04-2004, 08:49 PM
  5. First (semi) usefull program. Big accomplishment for me.
    By imortal in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2003, 12:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21