Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XOPEN_SOURCE
- #include <unistd.h>
- #include <stdio.h>
- #include <string.h>
- #include <cs50.h>
- #include <stdlib.h>
- #include <ctype.h>
- char salt[2];
- char pass[6];
- char alpha[] = {'\0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
- 't', 'u', 'v', 'w', 'x', 'v', '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', 'W', 'Z'};
- int main(int argc, string argv[])
- {
- //chechs if the argument count is 2, if not, prints how to use the program
- if (argc != 2)
- {
- printf("Usage: ./crack hash\n");
- return 1;
- }
- //calculates the salt that is needed for the crypt function
- for (int x = 0; x < 2; x++)
- {
- salt[x] = argv[1][x];
- }
- /*checks all possible passwords that starts with that symbol, once the password is found and correct,
- prints the password and ends the program as completed*/
- for (int i = 1, n = 53; i < n; i++)
- {
- pass[0] = alpha[i];
- for (int j = 0; j < n; j++)
- {
- pass[1] = alpha[j];
- for (int k = 0; k < n; k++)
- {
- pass[2] = alpha[k];
- for (int l = 0; l < n; l++)
- {
- pass[3] = alpha[l];
- for (int m = 0; m < n; m++)
- {
- pass[4] = alpha[m];
- //checks if the hashed password with that combination of symbols is the same as the given hash, if yes, prints the password and exits the program
- if (strcmp(crypt(pass, salt), argv[1]) == 0)
- {
- printf("%s\n", pass);
- return 0;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement