-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruzzle_cheater.cpp
336 lines (257 loc) · 8.35 KB
/
ruzzle_cheater.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <string.h>
#include <cstdlib>
#include <algorithm>
using namespace std;
// Struct to hold a point
struct Point2D{
int x;
int y;
};
// Global vars
char _fixedMap[4][4];
Point2D _pointMap[4][4];
// Function defs
void Init(string values);
vector<Point2D> Find(char* word);
vector<Point2D> FindLetter(char letter);
vector<Point2D> FindNext(vector<Point2D> pathSoFar, char* word);
vector<Point2D> FindNextLetter(Point2D currentPos, char letter, char localMap[4][4]);
void MoveOnPath(vector<Point2D> path);
string StartMovement(int x, int y);
string InterMovement(int x, int y);
string EndMovement();
// this function compares two strings and sorts them
bool myComparer (string a,string b) { return (a.size()>b.size()); }
int main()
{
string input;
cout << "please type your to crack key" << endl;
cin >> input;
string values = "gbbeieodslertjnr";
cout << " >" << input << "< "<< endl;
cout << "Checking the input value and copying" << endl;
cout << "Length of the input string: " << input.size() << endl;
if(input.size() == 16)
values = input.c_str();
//gbbe
//ieod
//sler
//tjnr
cout << "Initializing" << endl;
Init(values);
ifstream fin("dic.txt");
string worda;
vector<string> found_words;
cout << "Hello" << endl;
int words_found = 0;
while(getline(fin, worda))
{
unsigned pos = worda.find("/");
if(pos > 0 && pos < worda.size()){
worda.resize(pos);
vector<Point2D> path;
path = Find((char*)worda.c_str());
if(path.size() != 0)
{
if(std::find(found_words.begin(), found_words.end(), worda) != found_words.end()) {
cout << "double found" << endl;
} else {
found_words.push_back(worda);
}
//cout << worda;// << endl;
//MoveOnPath(path);
//cout << endl;
words_found++;
//break;
}
}
}
cout << "Total words found:" << words_found << endl;
sort(found_words.begin(), found_words.end(), myComparer);
for(int i = 0; i< found_words.size();i++)
{
cout << found_words[i];// << endl;
vector<Point2D> path;
path = Find((char*)found_words[i].c_str());
MoveOnPath(path);
cout << endl;
}
cin.get();
return 0;
}
// Send the commands to your android phone --------------------------------------------------------------------------------------------
void SendCommands(string comm)
{
stringstream commands;
commands << "adb shell \"" << comm << "\"";
system(commands.str().c_str());
}
// To initialize the fixed map of characters -----------------------------------------------------------------------------------------
void Init(string values)
{
for(int i = 0; i < 4; i++){
for(int j = 0;j<4;j++)
{
_fixedMap[i][j] = values[j+4*i];
}
}
// And initialize the coordinate map of your phone.
// These are the coords for a S4. (This is a big screen, so your coordinates might be different.)
int offset_x = 650;
int offset_y = 150;
int span_x = 925-offset_x;
int span_y = 400 -offset_y;
for(int i = 0; i < 4; i++){
for(int j = 0;j<4;j++)
{
_pointMap[i][j].x = offset_x + span_x*i;
_pointMap[i][j].y = offset_y + span_y*j;
}
}
}
// The 'Find' commands ----------------------------------------------------------------------------------------------------------------
vector<Point2D> Find(char* word)
{
vector<Point2D> startpoints;
startpoints = FindLetter(word[0]);
for(int i = 0; i<startpoints.size(); i++)
{
vector<Point2D> path;
path.push_back(startpoints[i]);
vector<Point2D> finalPath;
finalPath = FindNext(path, word);
if (finalPath.size() > 0)
return finalPath;
}
vector<Point2D> n;
return n;
}
vector<Point2D> FindLetter(char letter)
{
vector<Point2D> points;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (_fixedMap[i][j] == letter){
Point2D pt;
pt.x = i;
pt.y = j;
points.push_back(pt);
}
}
}
return points;
}
vector<Point2D> FindNext(vector<Point2D> pathSoFar, char* word)
{
char localMap[4][4];
for(int i = 0; i < 4; i++){
for(int j = 0;j<4;j++)
{
localMap[i][j] = _fixedMap[i][j];
}
}
for (int i = 0; i < pathSoFar.size(); i++)
{
localMap[pathSoFar[i].x][pathSoFar[i].y] = '#';
}
vector<Point2D> nexts = FindNextLetter(pathSoFar.back(), word[pathSoFar.size()], localMap);
if (nexts.size() == 0)
return nexts;
pathSoFar.push_back(nexts[0]);
if (pathSoFar.size() == strlen(word))
return pathSoFar;
return FindNext(pathSoFar, word);
}
vector<Point2D> FindNextLetter(Point2D currentPos, char letter, char localMap[4][4])
{
vector<Point2D> points;
for (int i = currentPos.x - 1; i <= currentPos.x + 1; i++)
{
if (i < 0 || i > 3)
continue;
for (int j = currentPos.y - 1; j <= currentPos.y + 1; j++)
{
if (j < 0 || j > 3)
continue;
if (localMap[i][j] == letter){
Point2D pt;
pt.x = i;
pt.y = j;
points.push_back(pt);
}
}
}
return points;
}
// Movement commands ------------------------------------------------------------------------------------------------------------------
void MoveOnPath(vector<Point2D> path)
{
stringstream commands;
for(int i = 0; i< path.size();i++)
{
if(i==0){
commands << StartMovement(_pointMap[path[i].x][path[i].y].y,_pointMap[path[i].x][path[i].y].x);
SendCommands(commands.str().c_str());
commands.str(std::string());
}
else
{
// Due to limited lenght of the adb shell commands we need to send this now and then in between
if(commands.str().size() > 800){
SendCommands(commands.str().c_str());
commands.str(std::string());
}
commands << InterMovement(_pointMap[path[i].x][path[i].y].y,_pointMap[path[i].x][path[i].y].x);
}
cout << "(" << path[i].x << ", " << path[i].y << ")";
}
SendCommands(commands.str().c_str());
commands.str(std::string());
commands << EndMovement();
SendCommands(commands.str().c_str());
}
string StartMovement(int x, int y)
{
stringstream commands;
// These commands start the swipe movement
commands << "sendevent /dev/input/event3 0003 57 50781;";
commands << "sendevent /dev/input/event3 0001 330 1;";
// These are the location commands
commands << "sendevent /dev/input/event3 0003 53 " << x << ";";
commands << "sendevent /dev/input/event3 0003 54 " << y << ";";
// These are related to the thickness of the push or something like that
commands << "sendevent /dev/input/event3 0003 50 3;";
commands << "sendevent /dev/input/event3 0003 60 45;";
// This is the 'end command train command'
commands << "sendevent /dev/input/event3 0000 0 0;";
return commands.str();
}
string InterMovement(int x, int y)
{
stringstream commands;
// These are the location commands
commands << "sendevent /dev/input/event3 0003 53 " << x << ";";
commands << "sendevent /dev/input/event3 0003 54 " << y << ";";
// These are related to the thickness of the push or something like that
commands << "sendevent /dev/input/event3 0003 48 5;";
commands << "sendevent /dev/input/event3 0003 50 5;";
// This is the 'end command train command'
commands << "sendevent /dev/input/event3 0000 0 0;";
return commands.str();
}
string EndMovement()
{
stringstream commands;
// These are the commands to finish the swipe gesture
commands << "sendevent /dev/input/event3 0003 57 4294967295;";
commands << "sendevent /dev/input/event3 0001 330 0;";
// This is the 'end command train command'
commands << "sendevent /dev/input/event3 0000 0 0;";
return commands.str();
}