#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <crypt.h>
int main(int argc, string argv[])
{
if(argc > 2){ printf("too many arguments\n"); return 51; }
if(argc < 2){ printf("too few arguments\n"); return 50; }
//if(strlen(argv[1]) > 4){ printf("Password is greater than 4 characters\n"); return 52; }
if(argc == 2) //make sure there are enough args
{
char hash_guess[] = "rofk";
//long long counter = 0;
//while(guess != argv[1]) //crypt(hash_guess, "50") != argv[1]) //while answer not correct
//{
for(int a = 65; a < 91; a++)
{
for(int b = 65; b < 91; b++)
{
for(int c = 65; c < 91; c++)
{
for(int d = 65; d < 91; d++)
{
for(int A = 0; A < 9; A = A + 5) //control if first is caps or not
{
for(int B = 1 ; B < 9 ; B = B + 5)//control if second is caps or not
{
for(int C = 2; C < 9; C = C + 5) //control if third is caps or not
{
for(int D = 3; D < 9; D = D + 5) //control if fourth is caps or not
{
hash_guess[0] = a;
hash_guess[1] = b;
hash_guess[2] = c;
hash_guess[3] = d;
hash_guess[A] = tolower(hash_guess[A]);
hash_guess[B] = tolower(hash_guess[B]);
hash_guess[C] = tolower(hash_guess[C]);
hash_guess[D] = tolower(hash_guess[D]);
printf("%s\n", hash_guess);
string cryptoguess = (crypt(hash_guess, "50"));
string input = argv[1];
if(cryptoguess == input) { return 0; }
}
}
}
}
}
}
}
//}
//}
//string guess = crypt(hash_guess, "50");
//printf("%lli", counter);
}
}
}
我試圖做一個程序,通過每4個字母的單詞去,開始對AAAA和去ZZZZ是增加了一些奇怪的事情FOOBAR。我完成了那部分。以密碼的地穴,使其不等於
作業的一部分是對其進行加密,如果加密與加密的密碼相匹配,那麼您知道您「密碼」了他們的密碼。當我比較加密的密碼,我手動輸入,並通過使用crypt函數出現的一個,它們是相同的,但在調試器中我看到了這一點,通過計算機加密爲:
"0x7ffff7dd9200 <_ufc_foobar+131200> "50k72iioeOiJU""
和我輸入的正常顯示
"0x7fffffffe34f "50k72iioeOiJU""
沒有_ufc_foobar的同樣的事情。有誰知道爲什麼那裏有,以及我如何擺脫它?
有沒有在你的代碼中沒有foobar的?這正是它所說的嗎? –
@ M.M那究竟是什麼意思?我是C的新手。 –
它們只是調試器中的內存地址偏移嗎?你說他們「比較」同樣的權利?當您將其打印到控制檯時,您會看到什麼? –