Last active
August 29, 2015 14:23
-
-
Save kgersen/6f389393ffa09d481600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>convert GGC codes</h2> | |
input and hit enter | |
<br> | |
<p>Code IATA <input id="iata" type="text" size=5></p> | |
<p>Code GGC <input id="ggc" type="text" size=5></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://lafibre.info/peering-google/ggc-google-global-cache-chez-sfr/msg239012/#msg239012 | |
import 'dart:html'; | |
import 'dart:convert'; | |
const String table = '1023456789abcdefghijklmnopqrstuvwxyz'; | |
String iata2sn (String iata) | |
{ | |
AsciiCodec c = new AsciiCodec(); | |
int aCode = c.encode('a').first; | |
List<int> iatan= c.encode(iata); | |
print(iatan); | |
print(iata.runes); | |
return iatan.map((int i) => table[((i-aCode)*7+5)%36]).join(); | |
} | |
String sn2iata (String sn) | |
{ | |
return sn.runes.map((int i) { | |
i=table.indexOf(new String.fromCharCode(i)); | |
i = (5-i%7)*5+i~/7+10; | |
return table[i]; | |
}).join(); | |
} | |
void main() { | |
InputElement sIata = querySelector('#iata'); | |
InputElement sGgc = querySelector('#ggc'); | |
sIata.onChange.listen((_) { | |
sGgc.value = iata2sn(sIata.value); | |
}); | |
sGgc.onChange.listen((_) { | |
sIata.value = sn2iata(sGgc.value); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment