forked from leonsbuddydave/F3Hacking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetwords.cpp
105 lines (82 loc) · 1.75 KB
/
getwords.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
using namespace std;
double Confidence = 40.0;
int Similar(string, string);
int main(int argc, char* argv[])
{
if (argc < 4)
{
cout << "Arguments: wordlength wordcount confidence" << endl;
return 1;
}
Confidence = (double)atoi(argv[3]);
ifstream InputFile;
stringstream ss;
ss << "words/" << argv[1] << ".txt";
InputFile.open(ss.str().c_str());
string Line;
string PreviousLine = "";
vector<string> Words;
while (1)
{
getline(InputFile, Line);
if (Line != PreviousLine)
{
PreviousLine = Line;
Words.push_back(Line.substr(0, atoi(argv[1])));
}
else
{
break;
}
}
// Starting word
srand( time(NULL) );
int randIndex = rand() % Words.size();
string StartWord = Words[randIndex];
Words.erase(Words.begin() + randIndex);
// Get a collection of all similar words
vector<string> SimilarWords;
SimilarWords.push_back( StartWord );
for (int i = 0; i < Words.size(); i++)
{
int Similarity = Similar( StartWord, Words[i] );
double Accuracy = (double)Similarity / (double)atoi(argv[1]) * 100.0;
if (Accuracy >= Confidence)
{
SimilarWords.push_back(Words[i]);
}
}
random_shuffle(SimilarWords.begin(), SimilarWords.end());
printf("%s", "{\"words\":[");
for (int i = 0; i < atoi(argv[2]); ++i)
{
printf("\"%s\"", SimilarWords[i].c_str());
if (i < atoi(argv[2]) - 1 )
{
if (i + 1 == SimilarWords.size())
break;
printf("%s", ",");
}
}
printf("%s", "]}");
}
int Similar(string One, string Two)
{
int similar = 0;
for (int i = 0; i < One.length(); i++)
{
if (One[i] == Two[i])
{
similar++;
}
}
return similar;
}