the 2nd function encodes word phase , 3rd 1 decodes same word function doesn't skip on spaces , punctuation.
def buildcipher(key): alpha="abcdefghijklmnopqrstuvwxyz" rest = "" letter in alpha: if not(letter in key): rest = rest + letter print key+rest def encode(string,keyletters): alpha="abcdefghijklmnopqrstuvwxyz" secret = "" letter in string: index = alpha.find(letter) secret = secret+keyletters[index] print secret def decode(secret,keyletters): alpha="abcdefghijklmnopqrstuvwxyz" clear = "" letter in secret: index = keyletters.find(letter) clear = clear+alpha[index] encode("this zest!!!" , "earthbcdfgijklmnopqsuvwxyz") #gives me sdfqfqzhqs #need give me sdfq fq zhqs!!! decode("tdfq fq zhqs!!!" , "earthbcdfgijklmnopqsuvwxyz")
at moment space character isn't in either alpha or keyletters - if don't want space encrypted add in same position in both.
note code ignores fact space in string encode not in keyletters. idea explicit in code - check letter present rather ignoring error.
Comments
Post a Comment