Skip to content

yenigma.py

pythonian23 edited this page Sep 3, 2020 · 9 revisions

Classes

Yenigma

  • imports warnings, Union from typing, and randomish

Table of Contents

method description
__init__ init method for Yenigma
set_base creates a basic set
create_rotors creates a set of rotors
create_rotor creates a singular rotor
create_reflector creates reflector
rotor_f returns a value through the rotor
rotor_b reverse direction of rotor_f
reflect returns a value through the reflector
rotate rotates a rotor

__init__(self)

  • init method for Yenigma
  • sets a default set of rotors

set_base(self, number_of_rings, ring_set="abcdefghijklmnopqrstuvwxyz")

  • sets the base ring set to ring_set, alphabet is default
  • saves the number of rings
  • sets up rotors
  • creates reflector
  • ties rotors and reflectors together in full_set

create_rotors(self, key)

  • checks for correct format and returns an error if it is not in the correct format
  • uses self.create_rotor to generate each key

create_rotor(self, key)

  • uses randomish.set_seed() to make each key return a different set of rings per key
  • uses randomish.random_int() to pop a character from temp_chars and appends the character to temp_rotor
  • saves temp_rotor to self.rotors

create_reflector(self, key)<a id="create_reflector>

  • uses randomish.set_seed() to make each key return a different set of rings per key
  • creates a reflector by selecting two random numbers that could be equal, and deleting them from temp_char

rotor_f(self, char, ring)

  • checks if char is a valid character and returns an empty string if it isn't
  • if char is valid, returns the swapped character from the selected ring

rotor_b(self, char, ring)

  • checks if char is a valid character and returns an empty string if it isn't
  • if char is valid, returns the swapped character from the selected ring
  • reverse of rotor_f

reflect(self, char)

  • same as rotor_f or rotor_b, but with the reflector
  • returns None

rotate(self, ring, quantity=1)

  • rotates the selected ring by the requested quantity
  • quantity's default is 1
  • does not change self.rotation; must be done separately