Python Forum
Enigma Machine, I need help!
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enigma Machine, I need help!
#21
Ok,

I don't know if i will be able to spend much time on this until Saturday.
You can get what's done by going to: https://github.com/Larz60p/Enigma
and downloading or cloning the entire repository,

This is the typical directory structure that I use. The __init__.py file that is a node
higher than the src directory, lets the python interpreter know where to find all modules.
You can add to this.

I'll be glad to pick up on Saturday, unless you feel that this is enough to get the general idea of how it should be structured.
If you create your own github repository, let me know when you are satisfied that all is there, and I'll remove the
one that I have in my area, or leave it there for a backup.

Only the basic GUI is done, at this point, didn't even get to the keyboard.

Let me know if you want me to continue.
Reply
#22
(Nov-18-2017, 01:48 AM)Larz60+ Wrote: Ok,

I don't know if i will be able to spend much time on this until Saturday.
You can get what's done by going to: https://github.com/Larz60p/Enigma
and downloading or cloning the entire repository,

This is the typical directory structure that I use. The __init__.py file that is a node
higher than the src directory, lets the python interpreter know where to find all modules.
You can add to this.

I'll be glad to pick up on Saturday, unless you feel that this is enough to get the general idea of how it should be structured.
If you create your own github repository, let me know when you are satisfied that all is there, and I'll remove the
one that I have in my area, or leave it there for a backup.

Only the basic GUI is done, at this point, didn't even get to the keyboard.

Let me know if you want me to continue.

I would be very grateful if you manage to finish this project! It would be a great help to me, and also show me how to "program better" in a sense.

I'd just have a question.. I downloaded the file on github, have it all here, but how do I execute it alltogether?? I can look into the file, change it or whatever, but execute all together? On Pyscripter, the interpreter that I use, you can enter a code, then execute it. what next? I tried with the first __init__ code, but it wouldn't read it.. There is probably an easy answer, but I have never done such yet, so I would be grateful if you showed me how!

Thank you a lot for your help! SO so grateful to have you!! :)
Reply
#23
you should be able to run by going into the src directory and running:
python NewEnigma.py
All other modules are imported into this one, but can be run by themselves
as well.

During development, I use an IDE (PyCharm) which allows me to do everything from within the IDE,
including running the debugger, the inspector, git, etc.

Once the project is complete, snippsat has a great tutorial on packaging (in the tutorials section of this foum)
which will get your project into Pypi, and allowing it to be loaded with pip.

I'd recommend that you get yourself an IDE. There are a ton available. It is very much a personal preference
as to what you use. I like PyCharm, others like atom,  but not idle, it's got too many issues.
google 'python IDE's' to check them all out.

If you write something that you want to sell, you may have to pay to use an IDE, but if open-source, almost
all have a community edition which is free (you can make a contribution, which is a nice gesture).

As far as finishing the project, I can do that, but you need to be patient, because I have several others I'm working
on, and also answer questions on he forum.
Reply
#24
Completely rewrote rotor  class, it's not tested, but code is on github, and here:
import string
import random


class Rotor:
    def __init__(self, starting_index=0, output_encoding=None, notch_index=None):
        '''
        Initialization
        :param starting_index: optional initial starting index
        '''
        self.current_index = 0
        self.input_encoding = list(string.ascii_uppercase)
        if output_string:
            self.output_encoding = output_encoding
        else:
            self.output_encoding = random.shuffle(list(string.ascii_uppercase))
        self.index = starting_index
        self.minmax = [0, 25]
        self.notch_index = notch_index
        self.advance_next_rotor = False

    def click(self):
        '''
        rotate rotor 1 click, if notch at click set advance flag
        :return:
        '''
        self.advance_next_rotor = False
        gotnotch = None
        self.current_index += 1
        if self.current_index > self.minmax[1]:
            self.current_index = self.minmax[0]

        self.advance_next_rotor = self.notch_index and self.notch_index == self.current_index

    def get_next_char(self, char_in):
        '''
        Advance Rotor and return encoded character and advance flag
        :param char_in:
        :return:
        '''
        self.click()
        charidx = self.input_encoding.index(char_in)
        return self.output_encoding[charidx], self.advance_next_rotor

    def show_encoding(self):
        '''
        return encoding info
        :return: input encoding, output encoding, notch index
        '''
        return self.input_encoding, self.output_encoding, self.notch_index

    def test_rotor(self):
        pass

if __name__ == '__main__':
    rot = Rotor()
    rot.test_rotor()
Reply
#25
Rotor.py pdated in github. 12-20-2017 5:44 GMT
almost complete, reverse rotation/forward rotation sync problem remaining
Reply
#26
(Nov-20-2017, 05:45 PM)Larz60+ Wrote: Rotor.py pdated in github. 12-20-2017 5:44 GMT
almost complete, reverse rotation/forward rotation sync problem remaining

Thank you very much, I believe you are running into a similar problem I was having, just that your program is way further developped than mine! ;) But I have to thank you a lot! I hope you find a solution and don't stay hanging where I am.. Good luck!
Reply
#27
I know what it is (I think) on the decoding, the rotor click has to occur after the letter has been decoded.
Also, a note i have added pathlib paths to the project.
In order to use these, the InitializeData.py module must be run. I just made a change to it, that will
assure the data directory exists before creating json files which hold all of the initialization data, and makes the program presentation much cleaner.
if you run that module, it will create the data directory and populate it with two json files, one for color,
and the other for rotor encoding for 8 rotors which are historically corret.

This is getting close to being 100 percent functional, as soon as it is, I'll add back your GUI, probably as a separate class
in a separate module.

Remaining :
  • fix final encoding, decoding for separate rotor.
  • Add reflector
  • Add Patch Board
  • create selection of 3 of 8 rotors, and write code
    to address interaction from slots and clips.
  • Re enable GUI
maybe a few more?
Reply
#28
Sounds as if you are making great progress and look forward to trying out the finished program.  May I ask which model are you basing your code on? 

(Nov-21-2017, 01:53 AM)Larz60+ Wrote: ...the rotor click has to occur after the letter has been decoded.

This should be true, both for the encode and decode process. It would be nice to have an actual machine to reverse engineer, but I suppose we should be happy with descriptions, pictures and some rather poor schematics.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#29
I found a great test sequence here: https://www.codesandciphers.org.uk/enigma/example1.htm
written by Tony Sale the original curator of the Bletchley Park Museum, which I will start using after I finish
my sleep (I have weird sleeping hours, 3 A.M. est to 6 A.M. est, then I get up and have breakfast, log on to
forum, sleep again until 11:30 A.M. est, part of senior living).

So, I was rotating the rotors forward when text was moving forward and reverse when code was moving in reverse
but rotor apparently is always moving forward, even on the return trip (reflector towards right rotor). Which makes
more sense.

The patch board should be quite simple.
Reply
#30
I have the Rotors totally worked out in my head, and hope to have that class wrapped up tonight.
I have a design for the patchboard, and output display also in my head, and hope to have at least a start
on that done tonight also. Let's see what the night brings.

I have been working on the assumption that the model is the Wehrmacht I. If I am in the wrong, please advise.

I will post whatever I have done on GitHub before quitting.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Numeric Enigma Machine idev 8 135 4 hours ago
Last Post: idev
  Enigma Decoding Problem krisarmstrong 4 631 Dec-14-2023, 10:42 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020