我正在获取此字符串的子字符串:
alpha = "*|^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!-? "
我正在使用python 2.7。 我的问题是,当我想在字符串中输入第二行时,使用/n并将/n作为单个子字符串
alpha = "*|^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!-? "
def main():
intp = raw_input("Do you want to encode or decode a message? (Encode, Decode, Encode2, Makefile) ")
if intp == "Encode":
message = raw_input("What is the message you want to encrypt? ")
encoded = keygen(message)
print encoded
if intp == "Decode":
mes = raw_input("What do you want to decode? ")
unen = unencode(mes)
print unen
#Get the first letter of a string
if intp == "Encode2":
bigmess()
if intp == "Makefile":
mfile()
def keygen(key):
encode = []
encode2 = ""
for i in range(len(key)):
ind = 0
ind = alpha.index(key[i])
ind=ind-3
x = alpha[ind]
encode.append(x)
encode.reverse()
return(encode2.join(encode))
def unencode(endmess):
mess = []
mess2 = ""
for i in range(len(endmess)):
inlist = alpha.index(endmess[i])
inlist+=3
mess.append(alpha[inlist])
mess.reverse()
return(mess2.join(mess))
def bigmess():
str1 = ""
list2 = []
f= open("bigmessage.txt","r")
if f.mode == "r":
cont = f.read()
list2.append(cont)
str1 = str(list2).strip('[]').strip('"')
keygen(str1)
def mfile():
f = open("bigmessage.txt", "w")
main()
目前没有回答
相关问题 更多 >
编程相关推荐