2 return char.codeUnitAt(0) - 'a'.codeUnitAt(0) + 1;
6 return rune - 'a'.codeUnitAt(0) + 1;
11 return new String.fromCharCode((num - 1) % 26 + 'a'.codeUnitAt(0));
14 var letters = new RegExp(r'[a-z]');
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));
27 String code2(String expanded_passphrase) {
28 String passphrase = letters.allMatches(expanded_passphrase).map((Match m) => m[0]).join();
33 passphrase.runes.forEach((int rune) {
34 c0 = c(o(c0) + o(c1) * alpha);
35 c1 = c(o(c1) + n(rune) * beta);
41 // "abcdefghijklmnopqrstuvwxyz".runes.forEach((int rune) {
42 // print('$rune : ${new String.fromCharCode(rune)} :: ${n(rune)} ${c(n(rune) + 28)}');
45 // for (var match in letters.allMatches('The quick ! broWn')) {
46 // print(match.group(0)); // 15, then 20
49 // print(letters.allMatches('The quick ! broWn').map((Match m) => m[0]).join());
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.";
54 // print(code1('the cat.'));
57 // print(code2('the cat.'));