-
Word Unscrambler
Hey folks, I've been working on this project for quite some time today, prolly around like 3 hours and it should be such a simple task!
Basically it reads a wordlist (wordlist.txt) and a scrambled wordlist (encrypted.txt). As for preparation I've only included one string in each file that contains the same thing. Check this out:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
unsigned int i =0;
unsigned int chardex =0;
unsigned int chardexE =0;
string decrypt_str;
string current_str;
string encrypt_str;
fstream wordlist("wordlist.txt",ios::in);
fstream encrypted("encrypted.txt",ios::in);
fstream decrypted("decrypted.txt",ios::out);
fstream log("log.txt",ios::out);
if(wordlist.is_open() && encrypted.is_open() && decrypted.is_open())
{
while(!wordlist.eof())
{
getline(wordlist,current_str);
getline(encrypted,encrypt_str);
log << "This prints whatever i want it to...yet..."
if(current_str.length() == encrypt_str.length())
{
log << "THIS DOES NOT PRINT! and they are equal fasho."
for(chardex=0;chardex<=current_str.length();chardex++)
{
for(chardexE=0;chardexE<=current_str.length();chardexE++)
{
if(current_str[chardex] == encrypt_str[chardexE])
{
decrypt_str[chardex] == encrypt_str[chardexE];
printf("decrypt[%i] = encrypt[%i]",chardex,chardexE);
decrypted << decrypt_str[chardex];
}
}
}
}
}
encrypted.close();
decrypted.close();
log.close();
}
else{
printf("Cannot open the files");
}
wordlist.close();
return 0;
}
Logically this is probably about 80% done, but I can't get anything to work after the .length() issue! Nothing prints so I'm pretty sure nothing happens. Any clue guys?
Thanks in advance
EDIT: btw I'm using GCC Compiler in Ubuntu
-
Print out the lengths. What do you think they are, and what does the machine think they are?
-
Okay so I added these two lines:
Code:
getline(wordlist,current_str);
getline(encrypted,encrypt_str);
log << "wordlist: " << current_str << " Length:" << current_str.length(); //here
log << "wordlist: " << encrypt_str << " Length:" << encrypt_str.length(); //and here :)
and I'm beginning to get somewhere....I'll be back haha
thanks for the quick response man big ups
EDIT: Okay now I added a +1 to encrypt_str.length()....and its beginning to work
-
You started out good, but your post didn't actually ask anything. "I've got two lists... and some code." That's pretty much all your post said. Next time, actually ask a question, or explain what you want and how that's different from what you're getting. Ask smart questions.
Quzah.