The code for this I have put on GitHub, usage is as follows.
var demo1 = TypeX.init('01234', '00100', 'AOAKN', 'This is the string to be encoded'); //demo1 == KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY
var demo2 = TypeX.init('01234', '00100', 'AOAKN', 'KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY'); //demo2 == THISXISXTHEXSTRINGXTOXBEXENCODED
TypeX.init() accepts the following parameters:
- Which rotors to use
- The orientation of the rotors. 1 = reversed
- The indicator key (the starting position for each rotor)
- Text to encipher / decipher
The majority of this code is based on that of the Enigma - their workings are very similar, with a few exceptions such as fixed position rotors (stators), and the rotors could be inserted in reverse.
Unfortunately the wirings of the Typex have never been disclosed or recovered. Unlike the Enigma the Typex had many more inserts which have mostly been destroyed, GCHQ have the only Typex insert collection that I know of from which the wirings could easily be recovered using a continuity tester. So, the wirings that I have used in this simulator are those of the Enigma as recovered by Rejewski.