import sys
alphabet = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
rotor1 = ("p","l","m","k","o","n","j","i","b","h","u","v","g","y","c","f","t","x","d","r","z","s","e","a","w","q")
rotor2 = ("e","b","h","r","k","a","s","t","i","u","m","z","g","y","q","v","d","l","c","x","n","w","o","p","f","j")
rotor3 = ("test")
rotors = (alphabet,rotor1,rotor2,rotor3)
reflector = ("test")
def menu():
print "Welcome to the Enigma machine!"
print "------------------------------"
print "1) Encrypt your message"
print "2) Change the connections on the plugboard"
print "3) Exit the program"
userchoice = raw_input("Please choose an option")
if userchoice == "1":
encrypt()
elif userchoice == "2":
plugboard()
elif userchoice == "3":
sys.exit()
def encrypt():
alphapos = []
rotor1pos = []
encryptedword = []
userinput = raw_input("Please enter the message that needs to be encrypted")
usermsglist = list(userinput)
for x in range(0,2):
for i in range(0,len(usermsglist)):
alphapos.append(rotors[x].index(usermsglist[i]))
encryptedword.append(rotor1[alphapos[i]])
usermsglist = ''.join(encryptedword)
print usermsglist
나는 내 코드를 내 enigma 기계에 더 효율적으로 사용하기 위해 for 루프를 만들려고 노력하고있다. 내가목록에서 파이썬으로 목록 내부에 추가하기
내가 오류를 얻을 목록 알파벳에게 인 로터리스트 내 항목에서 추가 할 때 나는 오류가
IndexError: string index out of range
이 오류를 구체적으로 로터를 일으키는 코드의 라인은 [이다 X] 부분하지만 난이 프로그램을 알파벳을 변경하면 잘 작동 : 모든
alphapos.append(rotors[x].index(usermsglist[i]))
A [최소한의 예]를 입력하십시오 (HTTP 만 0 번째에는 첫 번째 요소가 없습니다 ://stackoverflow.com/help/mcve), 올바른 형식으로되어 있으며 전체 오류 추적입니다. – jonrsharpe
여기서는 rotor3입니까? –
오류가 발생한 행은 무엇입니까? –