Skip to content

Commit

Permalink
Added some extra detail to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rd13 committed Mar 13, 2013
1 parent e84cf5d commit 5bbcc81
Showing 1 changed file with 7 additions and 42 deletions.
49 changes: 7 additions & 42 deletions README.md
@@ -1,58 +1,25 @@
# TypeX Emulation # TypeX Emulator


This is a Javascript implementation of the British Rotor Cipher Machine - [TypeX][2]. The Enigma has been used as a basis for this code as they have very similar workings, this version is a translation to Javascript from a [version written in C][1]. This is a Javascript implementation of the British Rotor Cipher Machine - [TypeX][2].


Improvements that I have made to the original code include: ##### Example 1 - Enciphering

1. No longer relies on files for input / output.
2. I have broken down the transformation into a better (more readable) format:

The transformation steps are:

* Input ->
* Right Stator ->
* Left Stator ->
* Right Rotor ->
* Middle Rotor ->
* Left Rotor ->
* Reflector ->
* Left Rotor ->
* Middle Rotor ->
* Right Rotor ->
* Left Stator ->
* Right Stator ->
* Output

3. I wrote this with the intention of using it in a brute force attack. To do this we can iterate through all possible rotor settings / orientations. Please see brute_force.js for an example.

4. Input validation is cleaner.

5. Removed goto's, general housekeeping.

6. Speed is almost double to that of the C implementation due to caching and no file read / writes (which helps when it comes to brute forcing).

##### Example 1 - Encoding
```javascript ```javascript
var demo1 = TypeX.init('01234', '00100', 'AOAKN', 'This is the string to be encoded'); var demo1 = TypeX.init('01234', '00100', 'AOAKN', 'This is the string to be encoded');
//demo1 == KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY //demo1 == KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY
``` ```


##### Example 2 - Decoding ##### Example 2 - Deciphering
```javascript ```javascript
var demo2 = TypeX.init('01234', '00100', 'AOAKN', 'KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY'); var demo2 = TypeX.init('01234', '00100', 'AOAKN', 'KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY');
//demo2 == THISXISXTHEXSTRINGXTOXBEXENCODED //demo2 == THISXISXTHEXSTRINGXTOXBEXENCODED
``` ```


##### Brute Force ##### Brute Force Decipher


The code in brute_force.js loops through every possible rotor position and orientation. It then inserts (in batches) the results into a Mongo collection. The code in brute_force.js loops through every possible rotor position and orientation. It then inserts (in batches) the results into a Mongo collection.


To run this Javascript you will need Node with the [native Mongo module][3] installed. To run this Javascript you will need Node with the [native Mongo module][3] installed.


The brute force method assumes that we know the indicator key.

The indicator key is 5 letters (A-Z), that indicate the starting position of each rotor.

```javascript ```javascript
//Rotor orientations (5^2) //Rotor orientations (5^2)
for (r1 = 0; r1 <= 1; r1++) { for (r1 = 0; r1 <= 1; r1++) {
Expand All @@ -77,11 +44,9 @@ if((/(\d)(?=.*\1)/).test(rotorPos)) continue;
var cipher_text = TypeX.init(rotorPos, rotorOri, 'AOAKN', 'KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY'); var cipher_text = TypeX.init(rotorPos, rotorOri, 'AOAKN', 'KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY');
``` ```
In the above example, there are 215,000 possible rotor settings, we can then harvest them into a database for further processing. The brute force method assumes that we know the indicator key.
We can then crawl this database and search for cribs, or we can perform a common bigram / trigram count which is probably an easier way to reduce this number.
See brute_force.js for an example of how to add an ngram count to your database. In the above example, there are 215,000 possible rotor settings, after inserting them into our Mongo collection we can then reduce them by searching for cribs or by ordering them by their common bigram / trigram count.
[1]: http://scholarworks.sjsu.edu/cgi/viewcontent.cgi?article=1244&context=etd_projects [1]: http://scholarworks.sjsu.edu/cgi/viewcontent.cgi?article=1244&context=etd_projects
[2]: http://en.wikipedia.org/wiki/Typex [2]: http://en.wikipedia.org/wiki/Typex
Expand Down

0 comments on commit 5bbcc81

Please sign in to comment.