我的程序从文件 HashedPassword.txt 中检查给定的 4 位哈希,并将其与应该在 temp.txt 中的所有可能的 4 个大写字母可能性进行比较。
我的问题是,如果我的数组“alpha”的大小为 13 及以下,我的程序可以正常工作,在这种情况下,我的程序将点击 STRCMP if 语句并给我与 HashedPasswords.txt 中给出的哈希相对应的正确密码,任何东西大于 13 的数组将导致 STRCMP 打印出无停止“1”,因此找不到匹配项。
我怎样才能解决这个问题?
PS 我尝试改变 line 和 line2 的大小,使它们更大也会改变 strcmp 的输出。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void E(char *in, char *out);
int main()
{
FILE* file,*fp2,*fp3;
char input[5];
char pass[5];
char alpha[15]="ABCD";//EFGHIJKLMNOPQRSTUVWXYZ";
char compare;
char string[5];
int i,j,k,l,m,a;
size_t lsize=0;
char line[5];
char line2[5];
char output[5];
char newline[2]="\n";
char test[5];
char *r=NULL;
fp2=fopen("HashedPassword.txt","r");
fgets(line2,sizeof(line2),fp2);
printf("%s\n",line2);
fclose(fp2);
file=fopen("temp.txt","w");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
for(k=0;k<4;k++)
{
for(l=0;l<4;l++)
{
fprintf(file,"%c%c%c%c\n",alpha[i],alpha[j],alpha[k],alpha[l]);
}
}
}
}
fclose(file);
fp3=fopen("temp.txt","r");
while(getline(&r,&lsize,fp3))
{
E(r,output);
printf("%d\n",strcmp(output,line2));
if(!strcmp(output,line2))
{
printf("This is your password: %s\n",r);
break;
}
}
fclose(fp3);
}
void E(char *in, char *out)
{
out[0]=(in[0]&0x80)^(((in[0]>>1)&0x7F)^((in[0])&0x7F));
out[1]=((in[1]&0x80)^((in[0]<<7)&0x80))^(((in[1]>>1)&0x7F)^((in[1])&0x7F));
out[2]=((in[2]&0x80)^((in[1]<<7)&0x80))^(((in[2]>>1)&0x7F)^((in[2])&0x7F));
out[3]=((in[3]&0x80)^((in[2]<<7)&0x80))^(((in[3]>>1)&0x7F)^((in[3])&0x7F));
}