Write about base64 byte code conversion tools.

Encryption algorithm night managed to get in front of which platform, a document written in his explanation too brief, and his encryption codes must be wrong.

Fortunately, several attempts finally succeeded trial, wrote a five relatively the most troublesome interface, cancel orders, submit the order of what functions are implemented, find the interface quite troublesome to write debugging, the kind written Interface Platform on the convenience, copy and paste it.

 

 

This is better understood base64, a common alphabet typically 1 byte 8 test 'bit, three bytes' bit 24, it is to convert base64 three bytes into four bits of byte 6. It has an own character table, different numbers represent different characters.

There are a lot of this comparison chart online.

All bytecode, why use base64 transfer:

Because some of the early transport protocols, such as SMTP mail transfer protocol, can only transfer printable ASCII characters. 8Bit led to the original bytecode (range 0-255) exceeds the available range. For example, when a picture message transfer resources when one Byte value is 10111011B, corresponding to the decimal ASCII code 187 does not belong to the scope and therefore can not be transferred. This time, Base64 encoding application and birth, which uses 6bit character of the original expression of 8bit characters. Base64 can control characters even beyond the original ASCII code of the ASCII characters are converted into 6big printable characters.
It can also be used in:

  • Spam communicators use Base64 to avoid anti -spam tools, because the tools do not usually translate the message of Base64.
  • In LDIF file, Base64 encoded as string.

 

Know, why use, that I direct the following code to tell how to use.

 

import base64

s_b = '1234'.encode()
B1 = base64.b64encode (S_B)   # directly bytecode conversion 
Print (B1)

Print (base64.b64decode (B1) .decode ())   # then converted back by the decoder, and need of, can continue to decode the string. 

SB1 = ' 123456 ' .encode ()
B2 = base64.b64encode (SB1)   # because transcoding b64, need the original three characters split into four, such as over the original character is 
Print (B2)   # multiple of 3 to display all the letters corresponding to his own if not make up missing a few a few = number up to fill two.

'' ' Can occur following standard Base64 encoded character + and /, in the URL can not be directly used as parameters,
So we have a kind "url safe" base64 encoded, in fact, the characters + and / respectively become - and _: '' '

print('~' *100)
print(base64.b64encode(b'i\xb7\x1d\xfb\xef\xff'))     
print(base64.urlsafe_b64encode(b'i\xb7\x1d\xfb\xef\xff'))   
print(base64.b64decode(b'abcd++//'))
print(base64.urlsafe_b64decode(b'abcd--__'))


'' ' This is very simple, references, links which speak more carefully ' ''

 

Namedtuple saw a very interesting module yesterday morning, see if I can record write about tomorrow, just under the record with the io module in front of the re owed, in fact, write blog I feel my elderly really deepen learning and memory just fine

 

base64 I personally think that can only be said to be an open way of conversion, but definitely make up part of the encryption method, there is when you have found the last byte code == follow, they can want to try using base64 decoded, and then through the utf8 gbk or decoding.

Reference links:

https://blog.csdn.net/wufaliang003/article/details/79573512

https://blog.csdn.net/wo541075754/article/details/81734770

https://www.liaoxuefeng.com/wiki/1016959663602400/1017684507717184

 

 

Guess you like

Origin www.cnblogs.com/sidianok/p/11863818.html