-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
322 lines (284 loc) · 12.6 KB
/
Program.cs
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
using System;
using SafeCracker;
using SafeCracker.SafeResponses;
namespace SafeCrackConsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to safe cracker");
digitSolve digit = new digitSolve();
// digit.digitValid();
//
// digit.finalAnswer();
digit.numberCorrect();
digit.finalAnswer();
}
}
/*
* function
*
*/
class digitSolve
{
//public long safeKey = 0;
public Safe safe = new Safe();
// public void digitValid()
// {
// int i = 0;
//
// if (safe.IsOpen)
// {
// Console.WriteLine("You already solved it!");
// }
// else
// {
// Console.WriteLine("Let's crack some safes."); //debug print, I know it gets into this loop
//
// string fmt = "000000000";
// int firstAttempt = 000000000; //if "000000000" returns 0 correct never use 0 again
// //Console.WriteLine(firstAttempt.ToString(fmt));
// Response firstResp = safe.Attempt(firstAttempt.ToString(fmt));
// if (firstResp.Type == ResponseType.Valid)
// {
// ValidResponse checkCorrect = (ValidResponse)firstResp;
// if (checkCorrect.CorrectDigits >= 1) //zeros okay
// {
// for (int digit = 9; digit >= 0; digit--) //increment through digits
// {
// for (long curDig = 000000000; curDig <= (9 * (long)Math.Pow(10, digit)); curDig += (1 * (long)Math.Pow(10, digit))) //digit 9 use previous 8 digits + new digit x100000000
// {
// Console.WriteLine("Value of current digit: {0}", curDig);
//
// //change int i to string
// //use it for saft attempt
// //write that to console
// Console.WriteLine(i);
// i++;
//
// Response resp = safe.Attempt(curDig.ToString(fmt));
// if (resp.Type == ResponseType.Valid)
// {
// ValidResponse checkCorrect1 = (ValidResponse)resp;
// if (checkCorrect1.CorrectDigits >= 2)
// {
// safeKey += curDig;
// Console.WriteLine("Value of safeKey: {0}", safeKey);
// break;
// }
// }
//
//
// }
// }
// }
// else //no zeros
// {
// /*curdig starts at 0
// * digit value is <= 9 * (10 ^ digit - 1)
// * digit value increments by 1 * (10 ^ digit - 1)
// */
// for (int digit = 9; digit >= 0; digit--) //increment through digits
// {
// for (long curDig = 000000001; curDig <= (9 * (long)Math.Pow(10, digit)); curDig += (1 * (long)Math.Pow(10, digit))) //digit 9 use previous 8 digits + new digit x100000000
// {
// Console.WriteLine("Value of current digit: {0}", curDig);
//
// //change int i to string
// //use it for saft attempt
// //write that to console
//
//
//
// Response resp = safe.Attempt(curDig.ToString(fmt));
// if (resp.Type == ResponseType.Valid)
// {
// ValidResponse checkCorrect2 = (ValidResponse)resp;
// if (checkCorrect2.CorrectDigits >= 1)
// {
// safeKey += curDig;
// Console.WriteLine("Value of safeKey: {0}", safeKey);
// break;
// }
// }
// }
// }
// }
// }
//
//
//
// }
//
// }
public void finalAnswer()
{
//string fmt = "000000000";
string result = string.Join("", safeKey);
Response solved = safe.Attempt(result);
if (safe.IsOpen)
{
Console.WriteLine();
Console.WriteLine("The final safe key is {0}", safeKey);
if (1 == 1)
{
SuccessResponse gitErDone = (SuccessResponse)solved;
Console.WriteLine(gitErDone.Attempts);
}
Console.WriteLine("Safe was successfully opened.");
}
else
{
// safeKey = 0;
// digitValid();
}
}
//fill valid number array
int[] numValid = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };//need 1d array to store #valid
int[] safeKey = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
bool[] digitFound = { false, false, false, false, false, false, false, false, false };
//need 2d array to store value of digit in safe key
public void numberCorrect() //check each possible number on all digits and set flags if number is used
{
//string fmt = "000000000";
long allDigit = 0; //stores value of answer
//should use 10 guess
// for (int digit = 9; digit >= 0; digit--) //increment through digits
// {
// for (long curDig = 000000000; curDig <= (9 * (long)Math.Pow(10, digit)); curDig += (1 * (long)Math.Pow(10, digit)))
// {
// Console.WriteLine("Value of current digit is {000000000}", curDig);
// //Console.WriteLine("Value of alldigit is {000000000}", allDigit);
// allDigit += (digit * curDig);
// }
//
// }
for (int k = 0; k < 10; k++) //0-9 //decrement value, so now test 8xx,xxx,xxx
{
//Console.WriteLine("Current test value is {0}", k);
//decrement through numbers that have valid responses
//else write value such as 9xx,xxx,xxx and test if valid, going digit by digit, x9x,xxx,xxx , xx9,xxx,xxx do this until all flags have been filled.
while (numValid[k] > 0)//if digit has no valid numbers skip it when testing and use value from safekey e.g. 945,{#}x2,x33
{
int[] testKey = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (int arrayFill = 0; arrayFill > 0; arrayFill++)
{
testKey[arrayFill] = k;
Console.WriteLine(testKey[k]);
}
/*
//do all current digit except 1 is current digit -1
//move x-1 through digits e.g. 8999 -> 9899 -> 9989 -> 9998
for (int j = 0; j < 9; j++)
{
testKey[j] = k - 1; //create an array for testKey
//if #correct is lower than previous #correct store value in the previous digit/slot
//convert testKey array to string
string testResult = string.Join("", testKey);
Response resp = safe.Attempt(result);
if (resp.Type == ResponseType.Valid)
{
ValidResponse checkCorrect2 = (ValidResponse)resp;
}
}
}
*/
/*
string result = string.Join("", allDigit);
Response resp = safe.Attempt(allDigit.ToString(fmt));
if (resp.Type == ResponseType.Valid)
{
ValidResponse checkCorrectMax = (ValidResponse)resp;
if (checkCorrectMax.CorrectDigits >= 1) //This value has some correct digits
{
switch (digit) //Sets flags of correct values for each digit
{
case 0:
numValid[0] = checkCorrectMax.CorrectDigits;
break;
case 1:
numValid[1] = checkCorrectMax.CorrectDigits;
break;
case 2:
numValid[2] = checkCorrectMax.CorrectDigits;
break;
case 3:
numValid[3] = checkCorrectMax.CorrectDigits;
break;
case 4:
numValid[4] = checkCorrectMax.CorrectDigits;
break;
case 5:
numValid[5] = checkCorrectMax.CorrectDigits;
break;
case 6:
numValid[6] = checkCorrectMax.CorrectDigits;
break;
case 7:
numValid[7] = checkCorrectMax.CorrectDigits;
break;
case 8:
numValid[8] = checkCorrectMax.CorrectDigits;
break;
case 9:
numValid[9] = checkCorrectMax.CorrectDigits;
break;
default:
break;
}
}
else
{
switch (digit) //Sets flags of correct values for each digit
{
case 0:
numValid[0] = 0;
break;
case 1:
numValid[1] = 0;
break;
case 2:
numValid[2] = 0;
break;
case 3:
numValid[3] = 0;
break;
case 4:
numValid[4] = 0;
break;
case 5:
numValid[5] = 0;
break;
case 6:
numValid[6] = 0;
break;
case 7:
numValid[7] = 0;
break;
case 8:
numValid[8] = 0;
break;
case 9:
numValid[9] = 0;
break;
default:
break;
}
}
Console.WriteLine("numValid[9] = {0}", numValid[9]);
Console.WriteLine("numValid[8] = {0}", numValid[8]);
Console.WriteLine("numValid[7] = {0}", numValid[7]);
Console.WriteLine("numValid[6] = {0}", numValid[6]);
Console.WriteLine("numValid[5] = {0}", numValid[5]);
Console.WriteLine("numValid[4] = {0}", numValid[4]);
Console.WriteLine("numValid[3] = {0}", numValid[3]);
Console.WriteLine("numValid[2] = {0}", numValid[2]);
Console.WriteLine("numValid[1] = {0}", numValid[1]);
Console.WriteLine("numValid[0] = {0}", numValid[0]);
*/
}
}
}
}
}