fork download
  1. def substitution_cipher(msg: str, key: str) -> str:
  2. for i in range(0, len(msg)):
  3. if msg[i].isalpha():
  4. index = ord(msg[i]) - ord('A')
  5. msg = msg[:i] + key[index] + msg[i + 1:]
  6. return msg
  7. print(substitution_cipher('IN A HOLE IN THE GROUND THERE LIVED A HOBBIT.', 'ABCDIFGHEJKLMNUPQRSTOVWXYZ'))
  8. # your code goes here
Success #stdin #stdout 0.02s 8904KB
stdin
Standard input is empty
stdout
EN A HULI EN THI GRUOND THIRI LEVID A HUBBET.