GithubHelp home page GithubHelp logo

enigma's Introduction

Enigma

Your task is to implement a variant of an Enigma machine which encrypts messages in an alphabet consisting of n letters denoted by numbers {1,2,...,n}. Symbol 0 ends the message.

Rotors Wx={wx, 0, wx, 1,...,wx, n}and reflectors Ry={ry, 0, ry, 1,...,ry, n} are given as permutations of numbers {1,2,...,n} and simulate mechanical parts that can be used by an operator. The internal "wiring" of these parts does not change.

Typing a letter into the input encrypts it by passing it through the rotors into reflector and back through the rotors in the inverse sequence, as seen here. A stationary sequence of rotors and a reflector represent a simple substitution cipher, it is their movement which makes the decoding chalenging.

Each rotor can move counterclockwise by at most one step during each encoding. The first rotor moves before every encoding; therefore if the initial position of this single rotor is denoted by the last letter of the alphabet (i.e. n, see example I) the first letter is encoded according to substitutions as stated in the rotor's definition. Further rotors move according to rules outlined in scetion "Turnover notch positions" of this link and this section. Additional information about double stepping can be found here.

In case there are more than 3 rotors only the first 3 rotate.

Input can be thought as divided into two parts: definitions of pieces of the machine and p instructions how to encode a given message using some of those parts. Before encoding a message the machine is assembled from k out of m rotors and a single reflector (out of l) and the rotors are set to some initial positions. Refer to the input section for details.

Input: Defintions of parts of the machine:

n- number of letters (numbers) in the alphabet
m - number of rotors, followed by their definitions W0,...,Wm-1
    definition of rotor Wi - permutation of the alphabet
    number of letters which cause turnover, followed by these letters as in "Position of turnover notches" table
l - number of reflectors
definitions of reflectors R0,...,Rl-1 - permutation of the alphabet

A set of p tasks to perform:

each task consists of 2 parts: machine setup and a message to encrypt.

p number of tasks
k - number of rotors in the machine
k pairs K0,...,Kk-1 - where Ki=(j, t), where j is an index of a copy of rotor Wj and t is its initial position
    rotors are given in order from fastest to slowest
    initial position of a rotor - it is set as if it was rotated (no actual rotations occur) prior to encoding, e.g. 1 - rotor is set as stated in permutation, 2 - it is shifted by one letter, etc.
r index of a reflector Rr
a sequence of numbers separated by whitespaces to encrypt, ending with the 0 character

Output: encrypted sequences of numbers (without the 0 character)

enigma's People

Contributors

karolina002 avatar

Watchers

Karolina Bober avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.