alexlofty
alexlofty

Reputation: 19

Enigma like python script won't return anything

I am trying to make a encrypter, in a similar fashion to the enigma machine but no what I try, the variable "final_message" won't print anything but blank space

message = input("Please input a message. ").upper()
final_message = ""
shift = 0

rotor1 = ['D','M','T','W','S','I','L','R','U','Y','O',
'N','K','F','E','J','C','A','Z','B','P','G','X','O','H','V']

for i in range(len(message)):
  if ord(message[i]) == 32:
    final_message += "n"
  else:
    num = ord(message[i]) - 65 + shift
    if num > 25:
      num -= 26
      final_message += rotor1[num]

  shift+=1

print(final_message)

I pretty new to coding so I am wondering whether anyone can spot my mistake. I don't get any errors, my code just finishes without printing any letters

Upvotes: 1

Views: 47

Answers (1)

Ananay Mital
Ananay Mital

Reputation: 1475

It seems the indentation of final_message += rotor1[num] should be at the same level as that of if num > 25. Like this -

if num > 25:
    num -= 26
final_message += rotor1[num]

Upvotes: 2

Related Questions