IghaloGenesisOsasenaga/Cryptography

Decrypt malfunction in Enigma class

Opened this issue · 9 comments

The decrypt function has a problem I can't think of a way to solve.

def _decrypt(self):
        output = ""
        # Variable to store suspected sequences
        current_sequence = ""
        # Replacement dictionary for special characters
        replacement_dict = self._nulls
        # Boolean to know if the current_sequence variable is not empty
        in_sequence = False
        for char in self._lampboard:
            if not in_sequence and char in self._sequence_marker:
                # Start a sequence
                current_sequence += char
                in_sequence = True
            elif in_sequence:
                # Add a character to the current sequence if it's length is less than 3
                current_sequence += char
                if len(current_sequence) == 3:
                    # Current sequence has reached max length, so add the corresponding special character to the output if current_sequence is found in the dictionary else add all the letters in current sequence to the output
                    output += replacement_dict.get(current_sequence, current_sequence)
                    # Important reset
                    current_sequence = ""
                    in_sequence = False
            else:
                # Add character to output as character doesn't begin a null sequence and current_sequence is empty 
                output += char
        return output

This function actually gets called after decryption though. It's purpose is to replace special sequences in decrypted text with a special character mapped to the sequence.
E.g

input: HELLOHRLWORLD
return value: HELLO WORLD

Problem

  1. Test 1
input: JUSTHRLME
return value: JUSTHRLME
  1. Test 2
input: THISHRLFOOD
return value: THI)LFOOD

At first I thought the sequence of nulls for special characters would be good. But that didn't seem to work out in my head. So I'd really appreciate help on this.

If I'm getting this right, you have a function that's suppose to scrub a sequence of characters, and replace it with a special character after decryption, but the function does not work?

Yes it doesn't work as it supposed to. This is because my special character sequences are not unique.

So, does this mean you've figured it out already?

In the test2 is that ) a typo

Wait, I just read what you said about your special character sequence not being unique.
If it is not unique, then what other property can be used to differentiate it from randomly occurring sequences of characters just like it?

I am thinking of using indicators like an exclamation perse to tell that i'm about to enter a special sequence.

Okay, are you gonna implement it, or it's just a thought?

Just a thought for now