From 5bbcc81ee1c0e09ce9313fd72f22d41fe887ebc6 Mon Sep 17 00:00:00 2001 From: Stuart Rutter Date: Wed, 13 Mar 2013 22:39:16 +0000 Subject: [PATCH] Added some extra detail to readme --- README.md | 49 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 07d58f1..13bc570 100644 --- a/README.md +++ b/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: - -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 +##### Example 1 - Enciphering ```javascript var demo1 = TypeX.init('01234', '00100', 'AOAKN', 'This is the string to be encoded'); //demo1 == KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY ``` -##### Example 2 - Decoding +##### Example 2 - Deciphering ```javascript var demo2 = TypeX.init('01234', '00100', 'AOAKN', 'KLHESNYNIMQAZHIZROBHDZHKWRQFFRTY'); //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. 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 //Rotor orientations (5^2) for (r1 = 0; r1 <= 1; r1++) { @@ -77,11 +44,9 @@ if((/(\d)(?=.*\1)/).test(rotorPos)) continue; 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. - -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. +The brute force method assumes that we know the indicator key. -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 [2]: http://en.wikipedia.org/wiki/Typex