dimanche 28 mars 2021

How to delete randomly inserted characters at specific locations in a string?

I was previously working on a problem of String encryption: How to add randomly generated characters in specific locations in a string? (obfuscation to be more specific).

Now I am working on its second part that is to remove the randomly added characters and digits from the obfuscated String.

My code works for removing one random character and digit from the string (when encryption_str is set to 1) but for removing two, three .. nth .. number of characters (when encryption_str is set to 2, 3 or n), I don't understand how to modify it.

My Code:

import string, random
def decrypt():

    encryption_str = 2 #Doesn't produce correct output when set to any other number except 1

    data = "osqlTqlmAe23h"
    content = data[::-1]
    print("Modified String: ",content)
    
    result = []
    result[:0] = content

    indices = []
    for i in range(0, encryption_str+3): #I don't understand how to change it
       indices.append(i)

    for i in indices:
      del result[i+1]

    message = "".join(result)
    print("Original String: " ,message)

decrypt()

Output for Encryption level 1 (Correct Output)

enter image description here

Output for Encryption level 2 (Incorrect Output)

enter image description here




Aucun commentaire:

Enregistrer un commentaire