Skip to content

enigma_cipher.PlugBoard

The PlugBoard provides the mapping of each letter to another one. ach letter can be mapped to another letter only once. Mapping the letter 'A' with the letter 'T' will block this combination, not allowing mapping the letter 'T' with any other letter.

The PlugBoard class can be imported directly from the enigma_cipher package:

from enigma_cipher import PlugBoard

PlugBoard(plugged_keys=None, include_digits=False)

Initializes the PlugBoard from the given mapping of keys. It only takes alphabetic characters.

Parameters

  • plugged_keys Mapping[str, str], optional:
    Mapping for every single letter in pairs. It is not necessary to specify both directions as {"A": "B", "B": "A"}; the specification of {"A": "B", ...} is enough for the class to understand the connection is bidirectional. Any not specified letter is assumed as one without any connection to another letter. If not specified, all letters are plugged to themselves.
  • include_digits bool, default = False:
    If True, the PlugBoard will include the digits to be ciphered. As default, only letters are to be ciphered.

PlugBoard.cipher_character(character)

Parameters

  • character str:
    Letter to cipher through the component.

Returns

  • str:
    The character ciphered only through the PlugBoard.

Class methods

PlugBoard.random_map(include_digits=False)

Initializes the PlugBoard class with a random mapping. The mapping might contain all characters connected or only a few.

Parameters

include_digits: bool, default = False:
If True, the PlugBoard will include the digits to be ciphered. As default, only letters are to be ciphered.

Returns

  • PlugBoard:
    Initializes the PlugBoard class with a random mapping among the characters.

Properties

PlugBoard.plugged_keys

Returns

  • Mapping[str, str]:
    Configured keys mapping for all valid characters.

PlugBoard.contains_digits

Returns

  • bool:
    Whether if the component contains digits within its valid characters