-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
94 lines (85 loc) · 2.7 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
using System;
namespace CodeBreaker
{
class Program
{
static void Main(string[] args)
{
while (DoProgram())
{
Console.WriteLine();
}
}
public static bool DoProgram()
{
Console.WriteLine("what code type");
string codeType = Console.ReadLine();
Cracker cracker = null;
switch(codeType)
{
case "offset":
cracker = DoOffset();
break;
case "atbash":
cracker = DoAtbash();
break;
case "offset_atbash":
cracker = DoOffsetAtbash();
break;
case "keypad":
cracker = DoKeypad();
break;
default:
Console.WriteLine("enter valid type");
return false;
}
if(cracker == null)
{
return false;
}
Console.WriteLine("enter input to be cracked");
var input = Console.ReadLine();
Console.WriteLine(cracker.Crack(input));
return true;
}
private static Cracker DoOffset()
{
Console.WriteLine("enter the offset");
bool success = int.TryParse(Console.ReadLine(), out int offset);
if(!success)
{
Console.WriteLine("enter a valid number");
return null;
}
Cracker cracker = new Offset(offset);
return cracker;
}
private static Cracker DoKeypad()
{
Console.WriteLine("Enter the row number of the letters.");
int row_num = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the column number of the letters.");
int column_num = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the letters");
string letters = Console.ReadLine();
return new Keypad(row_num, column_num, letters);
}
private static Cracker DoAtbash()
{
Cracker cracker = new Atbash();
return cracker;
}
private static Cracker DoOffsetAtbash()
{
Console.WriteLine("enter the offset");
bool success = int.TryParse(Console.ReadLine(), out int offset);
if (!success)
{
Console.WriteLine("enter a valid number");
return null;
}
Cracker cracker = new OffsetAtbash(offset);
return cracker;
}
}
}