- Demand
- Enter a string of characters
- If you encounter lowercase or uppercase letters, convert, A--Z,B--Y,C--X, uppercase letters are also
- If it is a different character, output it as-is
- Judgment logic
- Lowercase letter cond_a_z
- Capital Letter Cond_a_z
- Neither lowercase nor uppercase else
- Specific judgments, such as lowercase letters: (uppercase is similar)
- Offset_a the character of the input is the distance from a, then (the distance back to Z = = The distance of the input character to a), in particular, the position of the final character Offset_z
- Offset_z the ASCII code of the final converted character
- Char_transfer through CHR, converted to get the final character
- Content_output = '. Join (text_output) # conversion format, if the direct output text_output, will get: [' z ', ' y ', ' x ', ' _ ', ' 3 ', ' 4 ', ' 9 ', ' = ', ' _ ', ' C ', ' B ', ' A '], not: ZYX_349=_CBA
- The code is as follows
1 #Coding:utf-82 #__author__ = ' Diva '3 #test Case ABC_349=_XYZ4 5 #var6Char_a = Ord ('a')7Char_z = Ord ('Z')8Char_a = Ord ('A')9Char_z = Ord ('Z')Ten One #func A defFun (text_input): -Text_output = [] - ifLen (text_input) < 1: the returnFalse - - forKinchRange (len (text_input)): -char =Text_input[k] +Char_ascii =Ord (char) -Cond_a_z = (char_ascii) >= char_a andChar_ascii <= Char_z#Small Letter Case +Cond_a_z = (char_ascii) >= char_a andChar_ascii <= Char_z#Capital Case A at ifcond_a_z: -Offset_a = Char_ascii-char_a -Offset_z = Char_z-offset_a -Char_transfer =chr (offset_z) - text_output.append (Char_transfer) - elifcond_a_z: inOffset_a = Char_ascii-char_a -Offset_z = Char_z-offset_a toChar_transfer =chr (offset_z) + text_output.append (Char_transfer) - Else: the text_output.append (char) *Content_output ="'. Join (Text_output)#Conversion Format $ Panax Notoginseng Print('the ciphertext entered is:'+ str (text_input))#must add str, the list is converted to STR, otherwise error, + can only link the same type - Print('the converted plaintext is:'+str (content_output)) the + #Main A if __name__=='__main__': theCipher_text = Raw_input ('Please enter the ciphertext you want to convert:') +Fun (Cipher_text)
- Test results
Python ciphertext converted to clear text