Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * crack.c
- *
- * Jody W Moore
- *
- * this program decrypts a password
- *
- *
- **/
- #include <cs50.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include "dictionary.h"
- #include <crypt.h>
- #define DICTIONARY "/home/jharvard/Dropbox/hacker2/large"
- #define LENGTH 45
- int main(int argc, string argv[])
- {
- if (argc != 2)
- {
- printf("please enter two aurguments: \n");
- return 1;
- }
- string cryptd = argv[1];
- string resultant = NULL;
- char temp_key[LENGTH +1];
- int loop = 0;
- // char word_num[LENGTH +1];
- // int num = 0;
- char salt[3];
- for (int i = 0; i <= 1;i++)
- {
- salt[i] = cryptd[i];
- }
- typedef struct node
- {
- char word[LENGTH + 1];
- struct node* next;
- }
- node;
- char* dictionary = DICTIONARY;
- FILE* inptr = fopen(dictionary, "r");
- if (inptr == NULL)
- {
- printf("Could not open %s.\n", dictionary);
- return 1;
- }
- while( loop == 0 )
- {
- // while there are words available
- while (fscanf(inptr,"%s\n",temp_key) != EOF)
- {
- node* new_node = malloc(sizeof(node));
- new_node->next = NULL;
- strcpy(new_node->word,temp_key);
- resultant = crypt(new_node->word,salt);
- printf("#1 the word is %s\n",new_node->word);
- if (strcmp(resultant,cryptd) == 0)
- {
- printf(" #2 The decrypted password is %s\n",new_node->word);
- loop = 1;
- break;
- }
- else
- {
- printf("#3 the hashed resultant is %s\n",resultant);
- /*
- for (int j = 0; j <=1000; j++)
- {
- sprintf(word_num,"%s%d",new_node->word,num);
- printf("#4 the word is %s\n",word_num);
- resultant = crypt(word_num,salt);
- if (strcmp(resultant,cryptd) == 0)
- {
- printf("The decrypted password is %s\n",new_node->word);
- loop = 1;
- break;
- }
- if (num == 1000)
- {
- num = 0;
- }
- num++;
- }
- */
- free(new_node);
- }
- }
- }
- fclose(inptr);
- }
Add Comment
Please, Sign In to add comment