3n16m4-m4ch1n3 中文文档教程

发布于 3年前 浏览 21 项目主页 更新于 3年前

3n16m4-m4ch1n3

臭名昭著的 谜机 的现代诠释,不受硬件和布线的限制。

要准确地重新实现原始机器,请参阅 Daniel Palloks 的精彩作品< /a>

Default state

const DEFAULT_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ .'.split('')

const DEFAULT_ROTORS = [
  { index: 1, id: 1 },
  { index: 1, id: 2 },
  { index: 1, id: 3 },
]

const DEFAULT_PLUGBOARD = null

cli

您可以在您的 cli 中使用该机器:

npm i -g 3n16m4-m4ch1n3
3n16m4-m4ch1n3 -m "HELLO WORLD"

将输出:BIMSUK .VOO

如果您:

3n16m4-m4ch1n3 -m "BIMSUK .VOO"

您将获得:HELLO WORLD

魔法 ✨

cli options

-m< /code>:必需,要编码的消息

-r:格式为“id-index id-index”的转子

-c:charset as quoted string "CHARSET"

-p:格式为“char-char char-char”的插件板

-v:打印更新的转子状态

示例:

3n16m4-m4ch1n3 \
-r "1-25 2-12 3-25" \
-c "qwertyuiopasdfghjklzxcvbnm ." \
-p "e-l o-h" \
-m "hello world"

输出:v abuitdyny

当然:

3n16m4-m4ch1n3 \
-r "1-25 2-12 3-25" \
-c "qwertyuiopasdfghjklzxcvbnm ." \
-p "e-l o-h" \
"v abuitdyny"

outputs: hello world

module

该包导出一个函数machine,你可以按如下方式使用它:

import { machine } from '3n16m4-m4ch1n3'

const { encodedMessage, rotors } = machine({
  message: 'HELLO WORLD',
})

你可以选择传递rotors,自定义字符集plugboard。 有关详细信息,请参阅类型定义。

Dependencies

这个包需要加密(seedrandom 需要)

Implementation details

因为这个包提供了多种配置(远远超过原始机器) ,提前生成所有可能的配置将需要限制字符集选择以及转子数量。

相反,它根据机器配置通过 seedrandom 使用种子随机数在运行时创建转子映射。

这允许多种可能的配置。

不是任何谜机版本内部工作的精确复制品,而是扩展可能配置数量的近似值。

Notable differences to original design

  • A letter can become itself
  • Character set is not limited to 26 latin chars
  • Lowercase and uppercase characters are not the same
  • Used rotor number is not limited to 3
  • Choice of available rotors is not limited to 7
  • Plugboard expands with character set

3n16m4-m4ch1n3

A modern interpretation of the infamous enigma machine not limited by hardware and wiring.

For an accurate re-implementation of the original machine, see the amazing work by Daniel Palloks

Default state

const DEFAULT_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ .'.split('')

const DEFAULT_ROTORS = [
  { index: 1, id: 1 },
  { index: 1, id: 2 },
  { index: 1, id: 3 },
]

const DEFAULT_PLUGBOARD = null

cli

You can use the machine in your cli:

npm i -g 3n16m4-m4ch1n3
3n16m4-m4ch1n3 -m "HELLO WORLD"

will output: BIMSUK .VOO

if you:

3n16m4-m4ch1n3 -m "BIMSUK .VOO"

you'll get: HELLO WORLD

magic ✨

cli options

-m: required, message to be encoded

-r: rotors in format "id-index id-index"

-c: charset as quoted string "CHARSET"

-p: plugboard in format "char-char char-char"

-v: print updated rotor state

Example:

3n16m4-m4ch1n3 \
-r "1-25 2-12 3-25" \
-c "qwertyuiopasdfghjklzxcvbnm ." \
-p "e-l o-h" \
-m "hello world"

outputs: v abuitdyny

Of course then:

3n16m4-m4ch1n3 \
-r "1-25 2-12 3-25" \
-c "qwertyuiopasdfghjklzxcvbnm ." \
-p "e-l o-h" \
"v abuitdyny"

outputs: hello world

module

The package exports a single function machine, you can use it as follows:

import { machine } from '3n16m4-m4ch1n3'

const { encodedMessage, rotors } = machine({
  message: 'HELLO WORLD',
})

You can optionally pass rotors, custom charset and plugboard. See type definition for details.

Dependencies

This package requires crypto (required by seedrandom)

Implementation details

As this package offers a HUGE variety of configurations (far more than the original machines), generating all possible configuration ahead of time would have required a limitation on charset choices as well as number of rotors.

Instead it uses a seeded random via seedrandom, based on machine configuration to create the rotor mappings at runtime.

This allows for a huge variety of possible configurations.

This is not an exact replica of the inner working of any enigma machine version, rather an approximation that expands on the possible number of configurations.

Notable differences to original design

  • A letter can become itself
  • Character set is not limited to 26 latin chars
  • Lowercase and uppercase characters are not the same
  • Used rotor number is not limited to 3
  • Choice of available rotors is not limited to 7
  • Plugboard expands with character set
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文