Removing files from data analysis directory
[ou-summer-of-code-2017.git] / 03-door-codes / day3.dart
1 int o(String char) {
2 return char.codeUnitAt(0) - 'a'.codeUnitAt(0) + 1;
3 }
4
5 int n(int rune) {
6 return rune - 'a'.codeUnitAt(0) + 1;
7 }
8
9
10 String c(int num) {
11 return new String.fromCharCode((num - 1) % 26 + 'a'.codeUnitAt(0));
12 }
13
14 var letters = new RegExp(r'[a-z]');
15
16 String code1(String expanded_passphrase) {
17 String passphrase = letters.allMatches(expanded_passphrase).map((Match m) => m[0]).join();
18 String c0 = passphrase[0];
19 String c1 = passphrase[1];
20 passphrase.substring(2).runes.forEach((int rune) {
21 c0 = c(o(c0) + o(c1));
22 c1 = c(o(c1) + n(rune));
23 });
24 return c0 + c1;
25 }
26
27 String code2(String expanded_passphrase) {
28 String passphrase = letters.allMatches(expanded_passphrase).map((Match m) => m[0]).join();
29 int alpha = 5;
30 int beta = 11;
31 String c0 = "r";
32 String c1 = "i";
33 passphrase.runes.forEach((int rune) {
34 c0 = c(o(c0) + o(c1) * alpha);
35 c1 = c(o(c1) + n(rune) * beta);
36 });
37 return c0 + c1;
38 }
39
40 void main() {
41 // "abcdefghijklmnopqrstuvwxyz".runes.forEach((int rune) {
42 // print('$rune : ${new String.fromCharCode(rune)} :: ${n(rune)} ${c(n(rune) + 28)}');
43 // });
44
45 // for (var match in letters.allMatches('The quick ! broWn')) {
46 // print(match.group(0)); // 15, then 20
47 // };
48
49 // print(letters.allMatches('The quick ! broWn').map((Match m) => m[0]).join());
50
51 String phr = "the traveller in the grey riding-coat, who called himself mr. melville, was "
52 "contemplating the malice of which the gods are capable.";
53
54 // print(code1('the cat.'));
55 print(code1(phr));
56
57 // print(code2('the cat.'));
58 print(code2(phr));
59 }