I have been working on crack lately, and I have been running into a lot of problems. Sorry, but lately I have been needing to be on here a lot, probably asking stupid questions. I want to thank you all for all the help you guys have given me so far. Here is my problem: My code works for everything except for passwords that are five characters. Where could I be going wrong? Here is my code. Thank you all so much and have a wonderful day.
#define _XOPEN_SOURCE
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
int main(int argc, string argv[])
{
clock_t tic = clock();
// Gets password and returns errors
if (argc <= 1)
{
printf("Error: Enter a password when running the program\n");
return 1;
} else if (argc >= 3)
{
printf("Error: Please only input one value");
return 2;
}
// Gets the salt and password
char salt[3] = {argv[1][0], argv[1][1]};
string password = argv[1];
// Alphabet
char* alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Passwords
char word[5];
char* crypted;
// Main function
for (int i = 0; i < 52; i++)
{
// One character password
word[0] = alpha[i];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0) {
goto PRINT;
}
}
// Two characters
for (int i = 0; i < 52; i++)
{
// One character password
word[0] = alpha[i];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0) {
goto PRINT;
}
for (int j = 0; j < 52; j++)
{
// Two character password
word[1] = alpha[j];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
}
}
// Three Characters
for (int i = 0; i < 52; i++)
{
// One character password
word[0] = alpha[i];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int j = 0; j < 52; j++)
{
// Two character password
word[1] = alpha[j];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int k = 0; k < 52; k++)
{
word[2] = alpha[k];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
}
}
}
for (int i = 0; i < 52; i++)
{
// One character password
word[0] = alpha[i];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int j = 0; j < 52; j++)
{
// Two character password
word[1] = alpha[j];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int k = 0; k < 52; k++)
{
word[2] = alpha[k];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int l = 0; l < 52; l++)
{
// Four character password
word[3] = alpha[l];
crypted = crypt(word, salt);
if(strcmp(crypted, password) == 0)
{
goto PRINT;
}
}
}
}
}
for (int i = 0; i < 52; i++)
{
// One character password
word[0] = alpha[i];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int j = 0; j < 52; j++)
{
// Two character password
word[1] = alpha[j];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int k = 0; k < 52; k++)
{
word[2] = alpha[k];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int l = 0; l < 52; l++)
{
// Four character password
word[3] = alpha[l];
crypted = crypt(word, salt);
if(strcmp(crypted, password) == 0)
{
goto PRINT;
}
for (int m = 0; m < 52; m++)
{
// Five character password
word[4] = alpha[m];
crypted = crypt(word, salt);
if (strcmp(crypted, password) == 0)
{
goto PRINT;
}
}
}
}
}
}
PRINT: printf("password: %s\n", word);
clock_t toc = clock();
printf("Elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
return 0;
}