[Python] encode the 01 password in ASCII format into a string.

Source: Internet
Author: User

The question is from hacker.org's Challenge 'didactic Bytes '[Crypto]

A password consisting of 01 strings is provided to find the decrypted word.

01110101 01110011 01100101 00100000 01110111 01100101 01100100 01101110 01100101 01110011 01100100 01100001 01111001 00100000 01100110 01101111 01110010 00100000 01110100 01101000 01100101 00100000 01100001 01101110 01110011 01110111 01100101 01110010

It is observed that each 01 string is an 8-bit binary number starting with 0. Therefore, it is converted into a decimal range of less than 127, which is associated with the ASCII code.

---

 

s = "01110101 01110011 01100101 00100000 01110111 01100101 01100100 01101110 01100101 01110011 01100100 01100001 01111001 00100000 01100110 01101111 01110010 00100000 01110100 01101000 01100101 00100000 01100001 01101110 01110011 01110111 01100101 01110010"bit = s.split()dec = map(lambda x:int(x,2),bit)print ''.join(map(chr,dec))

 

---

Store the password in variable s as a string

Str. split () separates strings with spaces and saves the results to the bit list in the form of a list.

Use map to execute int (x, 2) on each string in the bit list, convert a string of binary numbers to decimal, and save the result list to dec.

Use chr () to convert the decimal number in the dec list to a character, and use str. join (iterable) to convert the character list to a string and output it.

Related Article

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.