Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <crypt.h>
- // easy password for testing:
- // aaaaa:50XcgR31jl/4M
- // from problem set docs:
- // anushree:50xcIMJ0y.RXo = YES
- // brian:50mjprEcqC/ts = CA
- // bjbrown:50GApilQSG3E2 = UPenn (takes a while)
- // lloyd:50n0AAUD.pL8g = lloyd (takes a while)
- // malan:50CcfIk1QrPr6 = maybe (takes a while)
- // maria:509nVI8B9VfuA = TF
- // natmelo:50JIIyhDORqMU = nope
- // rob:50JGnXUgaafgc = ROFL
- // stelios:51u8F0dkeDSbY = NO
- // zamyla:50cI2vYkF0YU2 = LOL
- bool crack(char *user_input, char *guess, char *salt);
- int main(int argc, string *argv[])
- {
- if (argc != 2) // prevent the user from not entering the correct number of command line arguments
- {
- printf("Invalid Hash Needed!:\n ");
- return 1;
- }
- string *user_input = argv[1]; // declare a pointer called user input (which we have also stated is argv[1])
- char salt[3];
- for (int i = 0; i < 2; i++)
- {
- salt[i] = *user_input[i];
- salt[2] = '\0';
- }
- string alphabet = "ABC";
- char guess[1];
- for (int a1 = 0; a1 < strlen(alphabet); a1++) // check onenote for how these forloops work
- {
- guess[0] = alphabet[a1];
- guess[1] = '\0';
- // The crypt function takes a password, key, as a string, and a salt character array which is described below, and returns a printable ASCII string which starts with another salt. It is believed
- // that, given the output of the function, the best way to find a key that will produce that output is to guess values of key until the original value of key is found.
- if (crack(alphabet, guess, salt))
- {
- printf("Password is: %s\n", guess);
- return 0;
- }
- }
- printf("\n");
- }
- // derefrencing the pointers for user input, guess[i]th index & salt at [i]th index in our crack function so we can update these pointers declared in main within this function
- // without having to fuck around with making copies of this data and passing it back etc
- bool crack(char *user_input, char *guess, char *salt)
- {
- char *encrypted_guess = crypt(guess, salt);
- if (strcmp(encrypted_guess, user_input) == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
Add Comment
Please, Sign In to add comment