IghaloGenesisOsasenaga / Cryptography

This is a repository exploring different encryption methods.
MIT License
1 stars 0 forks source link

Decrypt malfunction in Enigma class #1

Open IghaloGenesisOsasenaga opened 5 months ago

IghaloGenesisOsasenaga commented 5 months ago

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
  2. 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.

Osalotioman commented 3 months ago

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?

IghaloGenesisOsasenaga commented 1 month ago

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

Osalotioman commented 1 month ago

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

IghaloGenesisOsasenaga commented 1 month ago

No.

Osalotioman commented 1 month ago

In the test2 is that ) a typo

Osalotioman commented 1 month ago

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?

IghaloGenesisOsasenaga commented 1 month ago

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

Osalotioman commented 1 month ago

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

IghaloGenesisOsasenaga commented 1 month ago

Just a thought for now