-
Notifications
You must be signed in to change notification settings - Fork 0
/
e59.cs
37 lines (34 loc) · 1.22 KB
/
e59.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
using System.IO;
public class Euler59 {
public static char[] decode(char[] key) {
StreamReader reader = new StreamReader("cipher1.txt");
char[] message = new char[1201];
int i = 0;
do {
char c = (char) System.Convert.ToInt16(reader.ReadLine());
message[i] = (char)(((int)c) ^ ((int)key[i%3]));
i++;
} while (reader.Peek() != -1);
return message;
}
public static int Main(string[] args) {
for (char a = 'a'; a <= 'z'; ++a) {
for (char b = 'a'; b <= 'z'; ++b) {
for (char c = 'b'; c <= 'z'; ++c) {
char[] key = new char[3] {a,b,c};
char[] asciis = decode(key);
string message = new string(asciis);
if (message.Contains(" the ")) {
int ans = 0;
for (int i = 0; i < asciis.Length; ++i) {
ans += (int) asciis[i];
}
System.Console.WriteLine(ans);
return 0;
}
}
}
}
return 0;
}
}