TEST_F(XmlDocTest, PosdbGetMetaListNewDoc) { const char *url = "http://www.example.test/index.html"; char contentNew[] = "<html><head><title>my title</title></head><body>new document</body></html>"; XmlDoc xmlDocNew; initializeDocForPosdb(&xmlDocNew, url, contentNew); xmlDocNew.getMetaList(false); auto metaListKeys = parseMetaList(xmlDocNew.m_metaList, xmlDocNew.m_metaListSize); // make sure positive special key is there (to clear out existing negative special key) EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, POSDB_DELETEDOC_TERMID, false)); EXPECT_FALSE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, POSDB_DELETEDOC_TERMID, true)); // make sure title & body text is indexed // title EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "my"), false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "title"), false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "mytitle"), false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("my"), false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title"), false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("mytitle"), false)); // body EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("new"), false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("document"), false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("newdocument"), false)); /// @todo ALC add other terms }
bool GaddagFactory::pushWord(const Quackle::LetterString &word) { ++m_encodableWords; hashWord(word); // FIXME: This hash will fail if duplicate words are passed in. // But testing for duplicate words isn't so easy without keeping // an entirely separate list. for (unsigned i = 1; i <= word.length(); i++) { Quackle::LetterString newword; for (int j = i - 1; j >= 0; j--) newword.push_back(word[j]); if (i < word.length()) { newword.push_back(internalSeparatorRepresentation); // "^" for (unsigned j = i; j < word.length(); j++) newword.push_back(word[j]); } m_gaddagizedWords.push_back(newword); } return true; }
/* CheckTopTen ~ This function goes through the lyrics of the song to see if ~ the current song's frequency of a word should be stored in the top 10 */ void WordTable::CheckTopTen(Song* song){ for (size_t i = 0; i < song->lyrics.size(); i++){ uint32_t hash = hashWord(alphaOnly(song->lyrics[i])); wordNode* node = table[hash]; if (node->numSongs == 11){ //if top 10 songs + current song //currSong = the current song's info (song + word) SongFreq curr = node->songs_and_freqs[node->numSongs-1]; for (size_t j = 0; j < node->numSongs; j++){ //find song with minimum frequency of word size_t minIndex = j; SongFreq minSong = node->songs_and_freqs[j]; for (size_t k = 0; k < node->numSongs; k++){ if (node->songs_and_freqs[k].freq < minSong.freq){ minIndex = k; minSong = node->songs_and_freqs[k]; } } if (minSong.freq < curr.freq){ //swap if needed node->songs_and_freqs[minIndex] = curr; break; } } node->numSongs--; } } }
TEST_F(XmlDocTest, PosdbGetMetaListDeletedDoc) { const char *url = "http://www.example.test/index.html"; char contentOld[] = "<html><head><title>my title</title></head><body>old document</body></html>"; char contentNew[] = ""; XmlDoc *xmlDocOld = new XmlDoc(); mnew(xmlDocOld, sizeof(*xmlDocOld), "XmlDoc"); initializeDocForPosdb(xmlDocOld, url, contentOld); XmlDoc xmlDocNew; initializeDocForPosdb(&xmlDocNew, url, contentNew); xmlDocNew.m_deleteFromIndex = true; xmlDocNew.m_oldDocValid = true; xmlDocNew.m_oldDoc = xmlDocOld; xmlDocNew.getMetaList(false); auto metaListKeys = parseMetaList(xmlDocNew.m_metaList, xmlDocNew.m_metaListSize); // make sure negative special key is there (to indicate document is deleted) EXPECT_FALSE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, POSDB_DELETEDOC_TERMID, false)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, POSDB_DELETEDOC_TERMID, true)); // make sure title & body text from old document is deleted // title EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "my"), true)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "title"), true)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "mytitle"), true)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("my"), true)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title"), true)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("mytitle"), true)); // body EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("old"), true)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("document"), true)); EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("olddocument"), true)); /// @todo ALC add other terms }
/* analyzeSong ~ Processes song lyrics into the hash table: */ void WordTable::analyzeSong(Song* song){ for (size_t i = 0; i < song->lyrics.size(); i++){ if (load_factor() > LOADMAX) expand(); //expand if necessary uint32_t hash = hashWord(alphaOnly(song->lyrics[i])); if (table[hash] == NULL){ //if word doesn't exist in table //make new wordNode wordNode *node = new wordNode; node->word = alphaOnly(song->lyrics[i]); //first songs_and_freqs index initialized node->songs_and_freqs[0].song = song; node->songs_and_freqs[0].freq = 1; node->numSongs=1; table[hash] = node; numWords++; } else duplicateWord(hash, song); //word is in table already } }
/* search ~ Takes in a word, hashes it to find the word in the hash table ~ Creates a descending list of the songs_and_freqs array for that word. */ void WordTable::search(){ string word; //cout << "Put Word " << endl; cin >> word; uint32_t hash = hashWord(alphaOnly(word)); if (table[hash]!= NULL) { wordNode* node = table[hash]; Sort(node); //songs_and_freqs array now in descending order //calls printContext for (size_t i = 0; i < node->numSongs; i++){ printContext(node->songs_and_freqs[i].song, node->word); } } cout << "<END OF REPORT>" << endl; }
/* Function that brute force solves any unsolved passwords by trying every possible permutation for four-letter passwords. Passes in a pointer to an unsolvedPassword entry, and the solvedPasswords map by reference. */ void DictionaryDecrypter::bruteForceSolve(SolvedEntry* unsolvedPassword, std::map<int, DictionaryDecrypter::SolvedEntry*> &solvedPasswords){ // Initialization int digits[4] = { 0, 0, 0, 0 }; char potentialPassword[5] = { NULL }; unsigned char hash[20]; char hex_str[41]; /* Loop through all unsolved passwords and try each permutation four digits long until all passwords are solved. For loop of int i iterates 1679616 times because that is 36^4, the number of permutations of four characters. Digits: [0][1][2][3] Potential Password: [0][1][2][3] */ for (int i = 0; i < 1679616; i++){ if (digits[0] == 36){ // Carryover to tens digit digits[0] = 0; digits[1]++; } if (digits[1] == 36){ // Carryover to hundreds digit digits[1] = 0; digits[2]++; } if (digits[2] == 36){ // Carryover to thousands digit digits[2] = 0; digits[3]++; } // Always convert the ones digit to a character potentialPassword[0] = convertDigitToCharacter(digits[0]); // Only convert the tens digit to a character once a carryover to the tens digit has occurred if (i >= 36){ if (i == 36) digits[1] = 0; // Must initialize to 0, otherwise the carryover will increment // and just start at 1 potentialPassword[1] = convertDigitToCharacter(digits[1]); } // Only convert the hundreds digit to a character once a carryover to the hundreds digit has occurred if (i >= 1296){ if (i == 1296) digits[2] = 0; // Must initialize to 0, otherwise the carryover will increment // and just start at 1 potentialPassword[2] = convertDigitToCharacter(digits[2]); } // Only convert the thousands digit to a character once a carryover to the thousands digit has occurred if (i >= 46656){ if (i == 46656) digits[3] = 0; // Must initialize to 0, otherwise the carryover will increment // and just start at 1 potentialPassword[3] = convertDigitToCharacter(digits[3]); } digits[0]++; // Increment the ones digit here rather than earlier so [0000] is checked as a possible solution hashWord(potentialPassword, hash, hex_str); // Convert the permutation into hex if (unsolvedPassword->hex_str == hex_str){ // Check if the hex matches the unsolved password hex // If it does, store everything! unsolvedPassword->plainTextSolution = potentialPassword; std::pair<int, SolvedEntry*> newPair(unsolvedPassword->passwordEntryNumber, unsolvedPassword); solvedPasswords.insert(newPair); return; // Break out of this function because the password has been decrypted, don't need to try other permutations } } // Password was not able to be decrypted unsolvedPassword->plainTextSolution = "????"; std::pair<int, SolvedEntry*> newPair(unsolvedPassword->passwordEntryNumber, unsolvedPassword); solvedPasswords.insert(newPair); }
/// Hash function for the SPT. static int hashFingerprint(HashTable *table, StgWord64 key[2]) { // Take half of the key to compute the hash. return hashWord(table, (StgWord)key[1]); }
/// Hash function for the SPT. static int hashFingerprint(const HashTable *table, StgWord key) { const StgWord64* ptr = (StgWord64*) key; // Take half of the key to compute the hash. return hashWord(table, *(ptr + 1)); }
/* analyzeWord ~ Takes wordNodes from the oldTable and rehashes them */ void WordTable::analyzeWord(wordNode* wordNode){ uint32_t hash = hashWord(wordNode->word); table[hash] = wordNode; }
static int hashLock(HashTable *table, StgWord w) { Lock *l = (Lock *)w; // Just xor the dev_t with the ino_t, hope this is good enough. return hashWord(table, (StgWord)l->inode ^ (StgWord)l->device); }