Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cases not working in command line or with key files #1

Open
KipIngram opened this issue Mar 11, 2024 · 3 comments
Open

Test cases not working in command line or with key files #1

KipIngram opened this issue Mar 11, 2024 · 3 comments

Comments

@KipIngram
Copy link

KipIngram commented Mar 11, 2024

Hi. I can run your test program (in Python) fine:

[kipingram@lenovo]$ python test
BLA
THEXRUSSIANSXAREXCOMINGX

I modified it to print message key - that's the BLA above. As you see, the plaintext emerges.

But, when I try to use the command line utility as follows, it fails:

[kipingram@lenovo]$ ./pyenigma.py -r II IV V -u B -i 1 20 11 -p AV BS CG DL FU HZ IN KM OW RX -s WXC -t KCH
JRA

I've stared at the test program until I'm blue in the face, and as far as I can tell I've properly carried the settings over to the command line.

Any thoughts? I did this with a key file as well, and got JRA there too.

Here is the key "settings" part of the test python:

machine = EnigmaMachine.from_key_sheet(
       rotors='II IV V',
       reflector='B',
       ring_settings=[1, 20, 11],
       plugboard_settings='AV BS CG DL FU HZ IN KM OW RX')

# set machine initial starting position
machine.set_display('WXC')

# decrypt the message key
msg_key = machine.process_text('KCH')

Also, I modified the provided little keys.txt file so that today (the 10th) was one of the lines, and I tried to put in the same settings as above:

10 II IV V 1 20 11 AV BS CG DL FU HZ IN KM OW RX B
30 Beta II IV I A A A V 1/20 2/12 4/6 7/10 8/13 14/23 15/16 17/25 18/26 22/24 B-Thin

@gremmie
Copy link
Owner

gremmie commented Mar 11, 2024

Hi -

I'm rewriting my answer here as I've been away from this code for a very long time. You aren't the first person to get tripped up by this. The problem is that ring settings can be specified by a string, in which case the values are 1 based to be compatible with key sheets. But they can also be specified as an array, and in this case the values are 0 based. This is useful when you are programmatically trying to brute force settings or do hill climbing. There is a warning about this (search for "Warning") on this page: https://py-enigma.readthedocs.io/en/stable/guide.html

So the quick example is specifying an array, so it is 0-based (this is probably my mistake, I should have used a string here in the example). The command-line program is building a string from the arguments, so they have to be 1-based. So maybe try -i 2 21 12.

It's on my to-do list to update the documentation to make this clearer. I'm sorry about the frustration. Thanks for trying the software out.

@KipIngram
Copy link
Author

Aha - that fixed it:

[kipingram@lenovo]$ ./pyenigma.py -r II IV V -u B -i 2 21 12 -p AV BS CG DL FU HZ IN KM OW RX --start=WXC --text=KCH
BLA

Thanks very much, my friend!

@gremmie
Copy link
Owner

gremmie commented Mar 12, 2024

Great to hear! Thanks for the report and I'll hopefully make that better in the docs when I get some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants