Advertisement
go6odn28

imitation_game

Feb 15th, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. MOVE_LETTERS = "Move"
  2. INSERT_VALUE = "Insert"
  3. CHANGE_ELEMENT = "ChangeAll"
  4.  
  5.  
  6. def move_letters_of_code(secret_message, *args):
  7.     index_of_movement = int(args[0])
  8.  
  9.     left_part = secret_message[:index_of_movement]
  10.     right_part = secret_message[index_of_movement:]
  11.  
  12.     secret_message = right_part + left_part
  13.     return secret_message
  14.  
  15.  
  16. def insert_value_in_message(secret_message, *args):
  17.     index_of_inserting = int(args[0])
  18.     value_to_insert = args[1]
  19.  
  20.     part1 = secret_message[:index_of_inserting]
  21.     part2 = secret_message[index_of_inserting:]
  22.     secret_message = part1 + value_to_insert + part2
  23.  
  24.     return secret_message
  25.  
  26.  
  27. def change_elements_in_secret_message(secret_message, *args):
  28.     substring = args[0]
  29.     replacement = args[1]
  30.  
  31.     secret_message = secret_message.replace(substring, replacement)
  32.     return secret_message
  33.  
  34.  
  35. def main():
  36.     encrypted_message = input()
  37.  
  38.     command = input().split("|")
  39.     while command[0] != "Decode":
  40.         action = command[0]
  41.         args = command[1:]
  42.  
  43.         if action == MOVE_LETTERS:
  44.             encrypted_message = move_letters_of_code(encrypted_message, *args)
  45.         elif action == INSERT_VALUE:
  46.             encrypted_message = insert_value_in_message(encrypted_message, *args)
  47.         elif action == CHANGE_ELEMENT:
  48.             encrypted_message = change_elements_in_secret_message(encrypted_message, *args)
  49.  
  50.         command = input().split("|")
  51.  
  52.  
  53.     print(f"The decrypted message is: {encrypted_message}")
  54.  
  55.  
  56. if __name__ == "__main__":
  57.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement