나는 알파의 문자 (또는 그 반대)와 키에 문자를 교체하려고 해요 : 나는 문자열을 변경하려고 파이썬에서 단어 바꾸기?
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
key = "XPMGTDHLYONZBWEARKJUFSCIQV"
인코딩 될 수
(및 그 반대), 그렇게 말 "Hello"는 "LTZZE"가됩니다. 어떤 생각을 어떻게 할 것인가? str.maketrans 및 str.translateusrInput = 0
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
key = "XPMGTDHLYONZBWEARKJUFSCIQV"
def menu():
print "SECRET DECODER MENU"
print ""
print "1) Quit"
print "2) Encode"
print "3) Decode"
usrInput = raw_input("What would you like to do?")
return usrInput
def encodeWord():
plain = plain.upper()
length = len(plain)
encode = plain.encode(alpha, key)
return encode
def decodeWord():
coded = coded.upper()
length = len(coded)
decode = coded.decode(key, alpha)
return decode
def main():
keepGoing = True
while keepGoing:
usrInput = menu()
if usrInput == "2":
plain = raw_input("Text you want to be encoded: ")
encodeWord()
print encode(plain)
elif usrInput == "3":
coded = raw_input("Code you need to be decyphered: ")
decodeWord()
print decode(coded)
elif usrInput == "1":
print "Thanks for doing super secret spy stuff with me. No one seems to want to anymore. Goodbye.):"
keepGoing = False
else:
print "I don't know what to do! Ahhh!"
main()
저는 이것이 재미 있고 배우기 쉬운 문자열 작업을위한 단순한 excersice가되기를 바랍니다. 그것이 아니라면 - 그것을 사용하려고하는 사람들은 일대일 대체 암호가 펜과 종이 (그리고 꽤 많은 수학)로 분해 될 수 있기 때문에 큰 문제가되기 때문입니다. – J0HN
@ J0HN 걱정하지 마세요, 그것은 문자열 조작을위한 연습 일뿐입니다! –