Skip to content

igorbezsmertnyi/enigma-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enigma.js

Enigma.js


Enigma machine algorithm in javascript

Link to Demo

About Enigma Machine

The Enigma machines were a series of electro-mechanical rotor cipher machines developed and used in the early- to mid-twentieth century to protect commercial, diplomatic and military communication. Enigma was invented by the German engineer Arthur Scherbius at the end of World War I. Early models were used commercially from the early 1920s, and adopted by military and government services of several countries, most notably Nazi Germany before and during World War II. Several different Enigma models were produced, but the German military models, having a plugboard, were the most complex. However, Japanese and Italian models were also in use.


Enigma.js this is implementation of Enigma Machine algorithm in javascript

Enigma machine has 3 rotors and one reflector, onKeyDown event starting the algorithm works. The first keyCode is converted to a letter and this letter going to

Right Rotor

r_1 = (find(arr_alp, TxEncrypt) + find(arr_alp, TxKey3.value)) % 26
convert step. In the next step, converted in the first step letter, going to the
Middle Rotor

r_2 = (find(arr_alp, rotor_1[r_1]) + Module(find(arr_alp, TxKey2.value), find(arr_alp, TxKey3.value))) % 26
and the next to
Left Rotor

r_3 = (find(arr_alp, rotor_2[r_2]) + Module(find(arr_alp, TxKey1.value), find(arr_alp, TxKey2.value))) % 26
After all, their steps of converts are done, a letter is going to
Reflector
refl = (Module(find(arr_alp, rotor_3[r_3]), find(arr_alp, TxKey1.value))) % 26
and go back across Left Rotor, Middle Rotor and Right Rotor

On first keyDown event, r_1 got the first letter and first value from TxKey3 select and returned, they index in the arr_alp regular alphabet. In the second r_2 got r_1 value and finding an index of returned from rotor_1 alphabet, and sum it with Module of TxKey2 and TxKey3 indexes, 26 is the count of letters in the alphabet. In the third r_3 got r_2 index from rotor_2 alphabet and found index of this letter in the regular alphabet and was summing it with Module of TxKey1 select and TxKey2 select indexes from the regular alphabet. All next iteration are works similar to this there steps.

The find function returning the index of value from passed array
const find = (array, value) => {
if value not found, function returned -1

The Module function returning difference between to indexes, when indexes are equal 0, function returned 26. This need for prevent using letters from outside the limits keyCode values.


About

Enigma.js Enigma machine algorithm in javascript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published