Python ciphertext converted to clear text

Source: Internet
Author: User

  • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.