C 从2个文件中匹配文本

C 从2个文件中匹配文本,c,C,我编写了一个程序,该程序旨在通过搜索两个文本文件中存在的匹配哈希来恢复linux系统密码 #include<stdio.h> #include<string.h> #include<stdlib.h> #define MAXCHAR 1000 //Declaring Functions to match word in file int matchfile(char *shadowfilename, char*hashtablefilename); //sha

我编写了一个程序,该程序旨在通过搜索两个文本文件中存在的匹配哈希来恢复linux系统密码

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAXCHAR 1000
//Declaring Functions to match word in file
int matchfile(char *shadowfilename, char*hashtablefilename);
//shadowfilename for shadow.txt hashtablefilename for hash table
void UsageInfo(char *shadowfile, char * hashtablefile );
//Display usage info on arguements for program
void UsageInfo(char *shadowfile, char * hashtablefile) {
printf("Usage: %s %s <shadowfile> <hashtable>\n", shadowfile,hashtablefile);

}

//main function.
int main(int argc, char *argv[]) {
    int result, errcode;
    //Display format for user to enter arguements and
    //End program if user does not enter exactly 3 arguements
    if(argc < 3 || argc > 3) {
        UsageInfo(argv[1],argv[2]);
        exit(1);
    }


    system("cls");
//Pass command line arguements into searchstringinfile
    result = matchfile(argv[1], argv[2]);

//Display error message
    if(result == -1) {
        perror("Error");
        printf("Error number = %d\n", errcode);
        exit(1);
    }
    return(0);
}
//Declaring Functions to match word in file
//int matchfile(char *shadowfilename, char *hashtablefilename);
//shadowfilename for shadow.txt hashtablefilename for hash table

int matchfile(char *shadowfilename, char *hashtablefilename){

    FILE *shadowfile;
    FILE *hashtable;
    char strshadow[MAXCHAR];
    char strhash[MAXCHAR];


    shadowfile = fopen(shadowfilename, "r");
    if (shadowfile == NULL){
        printf("Could not open file %s",shadowfilename);
        return 1;
    }


    hashtable = fopen(hashtablefilename, "r");
    if (hashtable == NULL){
        printf("Could not open file %s",hashtablefilename);
        return 1;
    }

    //Getting text from the 2 files
    while (fgets(strshadow, MAXCHAR, shadowfile) != NULL &&fgets(strhash,MAXCHAR, 
    hashtable) != NULL){
    printf("%s", strshadow);
    printf("%s", strhash);
    int linenumber = 1;
    int search_result = 0;
            //Matching words line-by-line

    if((strstr(strshadow,strhash)) != NULL) {
        //Display line in which matched word is found
        printf("A match found on line: %d\n", linenumber);
        printf("\n%s\n", strhash);
        search_result++;
    }
    linenumber++;
}


fclose(shadowfile);
return 0;

}
shadow.txt。此文件包含纯文本形式的帐户用户名,并且是相应的哈希值。 格式如下:(用户):(散列)

如上所述,单词“banana”和“pyc1”阻止程序检测到这两个散列。 有人能告诉我需要做些什么改变来克服这个问题吗? 非常感谢。
编辑:阐明shadow.txt和hashtable.txt的格式在满足某些条件之前跳过字符串中的字符的最简单方法是:

char someString[MAXCHAR];

for (char* ptr = someString; *ptr != '\0'; ptr++) {
    if (conditionIsMet(ptr)) {
        doSomething();
        break;
    }
}

在您的情况下,
conditionIsMet(ptr)
应该将
*ptr
':'
进行比较,在这种情况下,密码散列位于
(ptr+1)
下(从下一个字符开始的字符串)。我认为您可以自己编写其余的代码。

因此您知道前几个字母会导致身份检查失败。是什么阻止你只比较第一个“?你好!很高兴再次见到你!你能指导我如何避免这种情况吗?解决方法很简单:学习更多C语言。需要做的事情很简单。
pyc1:$1$$Tnq7a6/C1wwyKyt0V/.BP/:17482:0:99999:7:::
char someString[MAXCHAR];

for (char* ptr = someString; *ptr != '\0'; ptr++) {
    if (conditionIsMet(ptr)) {
        doSomething();
        break;
    }
}