// XXXXXX Hi, I'm Cody.
// XXXXXX What's your name?
// XXXXXX Do you have a partner?
// XXXXXX If so, what's their name?

#include <crypt.h>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <string>
#include <unistd.h>

#include "ThreadPool.h"

using namespace std;

// Given a name to a file with line separated words, return a list of said words.
list<string> ParseDictionary(const string &filename);

// Returns an encrypted version of the given string.
string EncryptString(const string &str);

// XXXXXX You're gonna need stuff here.


int main(int argc, char *argv[]) {
  // This is the encrypted word that we want to crack.
  const string enc = "HAelkM0F2484A";

  if (argc != 2) {
    cerr << "Usage: ./hacky <dict-file>" << endl;
    return EXIT_FAILURE;
  }

  const list<string> words = ParseDictionary(argv[1]);
  cout << "Done reading dictionary..." << endl;

  // XXXXXX Stuff goes here.

  list<string>::const_iterator it = words.begin();
  for (; it != words.end(); ++it) {
    string str = *it;
    // XXXXXX Stuff goes here.
  }

  cerr << "NOT IMPLEMENTED" << endl; // XXXXXX You may need to change this but
  return EXIT_FAILURE;               // XXXXXX for now this FAILS.
}

// XXXXXX You're gonna need stuff here.


string EncryptString(const string &str) {
  struct crypt_data data;
  data.initialized = 0;
  return crypt_r(str.c_str(), "HA", &data);
}

list<string> ParseDictionary(const string &filename) {
  ifstream in(filename.c_str());
  list<string> words;
  
  if (in.fail())
    throw ios_base::failure("Error opening dictionary!");

  while (true) {
    string word;
    getline(in, word);
    if (in.eof())
      break;
    words.push_back(word);
  }
  
  in.close();
  return words;
}