Skip to content

Reflector

The reflector connects, in pairs, all the positions of the letters. This allows that an encoded text could be decoded with a machine having the same PlugBoard and Rotors configuration.

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

from enigma_cipher import Reflector

Reflector(mode="historical", custom_map=None, include_digits=False)

Initializes the reflector instance.

Parameters

  • mode Literal str:
    String defining the mapping of the reflector. The choices are:
    'historical' (default): The historical reflector (the one used at the original machine) is set.
    'random': The map among the letters is totally random.
    'custom': Allows setting a specific reflector configuration.
  • custom_map dict:
    Mapping of all characters. The mapping is only needed if mode='custom' is chosen. The characters must be specified in uppercase, and each character must be paired to only one another character. It supports having digits as characters to be ciphered.
  • include_digits bool, default = False:
    If True, the Reflector will include the digits to be ciphered. As default, only letters are to be ciphered. This value is only considered for 'random' mode, as its value is computed for 'custom' mode and set to False for 'historical' mode.

Reflector.reflect_character(character)

Returns the reflection of a given character.

Parameters

  • character str:
    Character to be reflected.

Returns

  • str:
    Reflection of the given letter.

Properties

Reflector.reflections_map

Returns

  • dict:
    Map that composes the reflector

Reflector.is_historical

Returns

  • bool:
    Whether the current reflector is defined in the historical configuration.

Reflector.contains_digits

Returns

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