Jodyone

crack.c

Aug 23rd, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.74 KB | None | 0 0
  1.  
  2. /**
  3.  * crack.c
  4.  *
  5.  * Jody W Moore
  6.  *
  7.  * this program decrypts a password
  8.  *
  9.  *
  10.  **/
  11.  
  12. #include <cs50.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. #include <stdlib.h>
  17. #include "dictionary.h"
  18. #include <crypt.h>
  19. #define DICTIONARY "/home/jharvard/Dropbox/hacker2/large"
  20. #define LENGTH 45
  21.  
  22. int main(int argc, string argv[])
  23. {  
  24.     if (argc != 2)
  25.     {
  26.         printf("please enter two aurguments: \n");
  27.         return 1;
  28.     }
  29.    
  30.     string cryptd = argv[1];
  31.     string resultant = NULL;
  32.     char temp_key[LENGTH +1];
  33.     int loop = 0;
  34.   //  char word_num[LENGTH +1];
  35.   //  int num = 0;
  36.     char salt[3];
  37.     for (int i = 0; i <= 1;i++)
  38.     {
  39.        salt[i] = cryptd[i];
  40.     }
  41.  
  42.     typedef struct node
  43.     {
  44.         char word[LENGTH + 1];  
  45.         struct node* next;
  46.     }
  47.     node;
  48.  
  49.    
  50.     char* dictionary =  DICTIONARY;
  51.     FILE* inptr = fopen(dictionary, "r");
  52.     if (inptr == NULL)
  53.     {
  54.         printf("Could not open %s.\n", dictionary);  
  55.         return 1;
  56.     }
  57.  
  58.     while( loop == 0 )
  59.     {
  60.              // while there are words available
  61.         while (fscanf(inptr,"%s\n",temp_key) != EOF)
  62.         {
  63.             node* new_node = malloc(sizeof(node));
  64.             new_node->next = NULL;
  65.             strcpy(new_node->word,temp_key);
  66.            
  67.             resultant = crypt(new_node->word,salt);
  68.              printf("#1 the word is %s\n",new_node->word);
  69.                 if (strcmp(resultant,cryptd) == 0)
  70.                 {
  71.                    
  72.                     printf(" #2 The decrypted password is %s\n",new_node->word);
  73.                     loop = 1;
  74.                     break;
  75.                  
  76.                 }
  77.                
  78.                 else
  79.                 {
  80.                    printf("#3 the hashed resultant is %s\n",resultant);
  81.                   /*
  82.                    for (int j = 0; j <=1000; j++)
  83.                    {
  84.                        sprintf(word_num,"%s%d",new_node->word,num);
  85.                        printf("#4 the word is %s\n",word_num);
  86.                        resultant = crypt(word_num,salt);
  87.                      
  88.                        if (strcmp(resultant,cryptd) == 0)
  89.                        {
  90.                             printf("The decrypted password is %s\n",new_node->word);
  91.                             loop = 1;
  92.                             break;
  93.                        }
  94.                        if (num == 1000)
  95.                        {
  96.                            num = 0;
  97.                        }
  98.                        num++;
  99.                    }
  100.                    */
  101.                  
  102.                    free(new_node);
  103.                 }
  104.    
  105.              
  106.              
  107.         }
  108.     }
  109.     fclose(inptr);  
  110. }
Add Comment
Please, Sign In to add comment