Pythonchallenge 1: The decoding of Caesar's code

Source: Internet
Author: User

Topic:

Problem Solving Ideas:
According to the k→m,o→q,e→g in the figure, we can find that the K,o,e three letters are moved backwards by 2 bits. Caesar is said to be the first to use this encryption method, so it is named Caesar password. The basic idea is to encrypt and decrypt letters by moving a certain number of digits.
Implementation method:

Import STRINGOLD_CHR = "G FMNC wms Bgblr RPYLQJYRC gr ZW fylb. RFYRQ Ufyr AMKNSRCPQ ypc DMP. Bmgle GR GL ZW fylb GQ glcddgagclr ylb rfyr ' q UFW rfgq rcvr GQ QM Jmle. Sqgle QRPGLE.KYICRPYLQ () GQ PCAMKKCLBCB. LMU ynnjw ml RFC spj. " A = String.lowercaseb = a[2:] + A[:2]a_to_b = String.maketrans (A, b) new_chr = String.translate (old_chr,a_to_b) Print New_ch R

Method Explanation:

    1. The String.lowercase method will output a A-Z of these 26 letters, and if you want to output other contiguous letters, you can fragment them, such as string.lowercase[:7] will output ' ABCDEFG '.
    2. With shard processing, the first two of the 26 letters are moved to the end, forming a new sequence of all the letters moving backwards two bits.
    3. The String.maketrans method takes two parameters (From,to) to form a conversion table from the from to to, which is passed into the translate method as a parameter.
    4. The String.translate method accepts three parameters (String,table,deletechars). Where Deletechars is an optional parameter that is used to delete characters from the original string. The Translate method converts a string based on the conversion table.

Output:

I hope you didnt translate it by hand. Thats what computers is for. Doing it in by hand are inefficient and that's why the this text was so long. Using String.maketrans () is recommended. Now apply to the URL.

Finally, apply this method to the map in the URL and change the map to OCR to go to the next pass.

Pythonchallenge 1: The decoding of Caesar's code

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.