For example, I have an index text file that has 400+ English words, and then I have another text file with decrypted text on each line.
I want to check each English word in my index file with each line of my decrypted text file (so checking 400+ English words for a match per line of decrypted text)
I was thinking of using strncmp(decryptedString, indexString, 10)
because I know that strncmp terminates if the next character is NULL
.
Each line of my decrypted text file is 352 characters long, and there's ~40 million lines of text stored in there (each line comes from a different output).
This is to decrypt a playfair cipher; I know that my decryption algorithm works because my professor gave us an example to test our program against and it worked fine.
I've been working on this project for six days straight and this is the only part I've been stuck on. I simply can't get it to work. I've tried using
while(getline(&line, &len, decryptedFile) != -1){
while(getline(&line2, &len2, indexFile) != -1){
if(strncmp(decryptedString, indexString, 10) == 0){
fprintf(potentialKey, "%s", key);
}
}
}
But I never get any matches. I've tried storing each string in into arrays and testing them one character at a time and that didn't work for me either since it would list all the English words are on one line. I'm simply lost, so any help or pointers in the right direction would be much appreciated. Thank you in advance.
EDIT: Based on advice from Clifford in the comments, here's an example of what I'm trying to do
Let's say indexFile contains:
HELLO
WORLD
PROGRAMMING
ENGLISH
And the decryptedFile contains
HEVWIABAKABWHWHVWC
HELLOHEGWVAHSBAKAP
DHVSHSBAJANAVSJSBF
WORLDHEEHHESBVWJWU
PROGRAMMINGENGLISH
I'm trying to compare each word from indexFile to decryptedFile, one at a time. So all four words from indexFile will be compared to line 1, line2, line 3, line 4, and line 5 respectively.