{"id":18550907,"url":"https://github.com/marlonbarcarol/enigma-engine","last_synced_at":"2025-05-15T10:10:37.828Z","repository":{"id":36960121,"uuid":"330231444","full_name":"marlonbarcarol/enigma-engine","owner":"marlonbarcarol","description":"An encryption algorithm with the implementation of the enigma machine","archived":false,"fork":false,"pushed_at":"2023-04-24T08:59:57.000Z","size":734,"stargazers_count":1,"open_issues_count":8,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-23T22:38:40.033Z","etag":null,"topics":["cipher","cryptography","encryption","enigma","enigma-machine","javascript","substitution-cipher","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@enigmaciphy/engine","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marlonbarcarol.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-16T18:39:54.000Z","updated_at":"2023-05-31T14:00:31.000Z","dependencies_parsed_at":"2023-02-16T05:16:10.986Z","dependency_job_id":null,"html_url":"https://github.com/marlonbarcarol/enigma-engine","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marlonbarcarol%2Fenigma-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marlonbarcarol%2Fenigma-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marlonbarcarol%2Fenigma-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marlonbarcarol%2Fenigma-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marlonbarcarol","download_url":"https://codeload.github.com/marlonbarcarol/enigma-engine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cipher","cryptography","encryption","enigma","enigma-machine","javascript","substitution-cipher","typescript"],"created_at":"2024-11-06T21:06:03.359Z","updated_at":"2025-05-15T10:10:37.809Z","avatar_url":"https://github.com/marlonbarcarol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is an implementation of the enigma machine encryption algorithm. The cipher heavily relies on substitution.\n\n## Rotor\n\nIt substitutes an alphabet letter, representing the wiring of the rotor, the offset of the ring may be positioned in a different position of the alphabet. A letter may go through substitution throughout many rotors. Each time a letter is substited the rotor turns to the next letter.\nDue to it's \"turning\" nature, a sequence of the same character will produce a different ciphertext for each turn.\n\n### Rotor Notch\n\nThe point at which the next rotor position should be moved forward.\n\n### Rotor processing representation\n\nWe will assume the position AAA and rings AAA as well as the following wiring alphabet.\n\n```\nPosition          0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\nAlphabet          A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z\nShuffled Alphabet B  D  F  H  J  L  C  P  R  T  X  V  Z  N  Y  E  I  W  G  A  K  M  U  S  Q  O\n```\n\nSo we initially have the following mapping `A=B, B=D, C=F, D=H, [...]`.\n\n#### **Rotation**\n\nBefore processing anything the machine will rotate from 0 to 1.\n\n#### **Wiring shift**\n\nThe mapping will happen from position 1 (A) outputing D.\n\n```\n                     ⬇️\nPosition          0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\nAlphabet          A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z\nShuffled Alphabet B  D  F  H  J  L  C  P  R  T  X  V  Z  N  Y  E  I  W  G  A  K  M  U  S  Q  O\n```\n\n#### **Rotor's position reverse shift**\n\nThe output D from the wiring shift, which is at alphabet position 3 will be subtracted by the rotor's position, 3 - 1 = 2, thus the final output will be the letter C, which is located at position 2.\n\n## Reflector\n\nWorks like a bi-directional map. The reflector is usually fixed, meaning it does not rotates as oposed to the rotors.\n\n```\nA maps B then\nB maps A\n```\n\n## Plugboard\n\nMaps a letter to another letter for its substitution, same property seem by the reflector. The major benefit is the possibility of mapping letters as needed, thus adding another layer of complexity to the cipher. The plugboard is applied before anything as well as after everything, meaning it is the first substitution and also the last, happening twice.\n\n```\nA maps B then\nB maps A\n```\n\n## Usage:\n\n```\nnpm install @enigmaciphy/engine\n```\n\n```ts\n// -- ENCRYPTING\nimport { Cipher, CipherJSON } from '@enigmaciphy/engine';\n\nconst configuration: CipherJSON = {\n\talphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',\n\tplugboard: { wiring: 'AQRIJFHGDEWLTNSXBCOMZVKPYU' },\n\tentry: { wiring: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' },\n\trotors: [\n\t\t{ wiring: 'EKMFLGDQVZNTOWYHXUSPAIBRCJ', notches: ['Q'] },\n\t\t{ wiring: 'AJDKSIRUXBLHWTMCQGZNPYFVOE', notches: ['E'] },\n\t\t{ wiring: 'BDFHJLCPRTXVZNYEIWGAKMUSQO', notches: ['V'] },\n\t],\n\treflector: { wiring: 'YRUHQSLDPXNGOKMIEBFZCWVJAT' },\n\tchargroup: 5,\n};\nlet cipher = Cipher.fromJSON(configuration);\n\ncipher.encrypt('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');\n// XPJUP VYBRA QAJNY VAIXO UUWXO VVPDM LKVEK BHQIL DMAKH YL\n\n// -- DECRYPTING\n\n// To decrypt the cipher is instantiated again so the rotors will be on their initial position.\ncipher = Cipher.fromJSON(configuration);\n\ncipher.encrypt('XPJUP VYBRA QAJNY VAIXO UUWXO VVPDM LKVEK BHQIL DMAKH YL');\n// LOREM IPSUM DOLOR SITAM ETCON SECTE TURAD IPISC INGEL IT\n```\n\n---\n\nThe code output has been tested against the following existing machines:\n\n- Universal Enigma: http://people.physik.hu-berlin.de/~palloks/js/enigma/enigma-u_v25_en.html\n- Cryptii enigma machine: https://cryptii.com/pipes/enigma-machine\n\n**Note:** This application currently does not support ring settings.\n\n### Sources:\n\n- Hackaday - THE ENIGMA ENIGMA: HOW THE ENIGMA MACHINE WORKED: https://hackaday.com/2017/08/22/the-enigma-enigma-how-the-enigma-machine-worked/\n- CryptoMuseum - Enigma wiring: https://www.cryptomuseum.com/crypto/enigma/wiring.htm\n- Enigma rotation example: https://crypto.stackexchange.com/a/71233/81146\n- A1: Enigma https://www.cs.cornell.edu/courses/cs3110/2018sp/a1/a1.html\n- Detailed working through of Enigma encipherment: https://www.codesandciphers.org.uk/enigma/example1.htm\n\n### Debug\n\n**VSCode example**\n`F1` \u003e `Debug: Toggle Auto Attach` \u003e `Always` \u003e inside vscode own terminal \u003e `node --inspect ./node_modules/.bin/jest src/Configuration/Rotor/Rotor.spec.ts`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarlonbarcarol%2Fenigma-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarlonbarcarol%2Fenigma-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarlonbarcarol%2Fenigma-engine/lists"}