Garbled full (three)

zhaozj2021-02-08  239

Base64

Base64 and QUOTED-PRINTABLE will be included below are a coding standard for MIME (multi-part), multimedia email, and WWW hypertext, for transmitting non-text data such as graphics, sound, and fax). MIME is defined in RFC1341.

Base64 is now a maximum of a company today, almost all email software headeds it as a default binary code, which has become synonymous with today's email coding.

Below is an example of Base64, from the example, you can also see the close contact of the Base64 and email:

Content-type: text / plain; charset = "CN-GB"

Content-Transfer-Encoding: Base64

CQKJICAGIKG2WTLC68VJT6I088IROBCNCGNX99XFOM1VZ2FVO6YW19TGU8A619W O6H0ZWXUZXQ6

Ly8ymdiumtemteyljiwljezmjoym6ops8nusagjdqioMiiCagxkq438jtvp65pnf3ytkjumh0dha6

LY9TB2DHBY5IZW50AXVULM5LDA0KCQKJRW1HAWX0BZPTB2DHB0AZNZEUBMV0DQOJICAGKIOQKIOQ

KioqkioqkioqkioqkioqkioqkioqkioqkioqkioqkioqkioqkioqiCagicagicagicagicagdqoj

ICAGKICZ / CHLVMFS5MQYW7S2VLK7TPJX36OS / 3BY9FJVKPKSSO0TRYYU8H0Z8IQDQOJICAGKIOQ

Kioqkioqkioqkioqkioqkioqkioqkioqkioqkioqkioqkioqkioqkioq

You can separate it into a file, you can name: mogao.eml, double-click to open with Outlook (the original information of the first two behaviors, starting from the fourth line as coding content).

Base64 algorithm is close to UUENCODE algorithm, it is also very simple: it puts the character flow order into a 24-bit buffer, and makes a missing place to make up. Then the buffer is truncated into 4 parts, the high position is first, each of the 6 digits, and the following 64 characters are reprecired: "AbcdefghijklmnopqrStuvwxyzabcdefghijklmnopqrStuvwxyz0123456789 /". If the input is only one or two bytes, then the output will be allowed to make up with the equal sign "=". This can partition the additional information causes the encoding confusion. It is generally 76 characters per row.

Below I give the Base64 encoding and decoded C language description:

/ * Base64 code * /

Void Base64 (unsigned char chasc [3], unsigned char chuue [4])

/ *

CHASC: Uncoded binary code

Chuue: Coded Base64 code

* /

{

INT I, K = 2;

UNSINGED CHAR T = NULL;

For (i = 0; i <3; i )

{

* (chuue i) = * (chasc i) >> K;

* (chuue i) | = t;

T = * (chasc i) << (8-k);

T >> = 2;

K = 2;

}

* (chuue 3) = * (chasc 2) & 63;

For (i = 0; i <4; i )

IF ((* (chuue i)> = 0) && (* (chuue i) <= 25)) * (chuue i) = 65; ELSE IF ((* (chuue i)> = 26) && (* (chuue i) <= 51)) * (chuue i) = 71;

ELSE IF (* (Chuue I)> = 52) && (* (chuue i) <= 61)) * (chuue i) - = 4;

ELSE IF (* (chuue i) == 62) * (chuue i) = 43;

ELSE IF (* (chuue i) == 63) * (chuue i) = 47;

}

/ * Base64 decoding * /

Void unbase64 (unsigned char chuue [4], unsigned char chasc [3])

/ *

Chuue: Unresolved Base64 code

CHASC: Decoded binary code

* /

{INT I, K = 2;

UNSIGNED Char t = NULL;

For (i = 0; i <4; i )

IF ((* (chuue i)> = 65) && (* (chuue i) <= 90)) * (chuue i) - = 65;

ELSE IF ((* (Chuue I)> = 97) && (* (chuue i) <= 122)) * (chuue i) - = 71;

ELSE IF ((* (Chuue I)> = 48) && (* (chuue i) <= 57)) * (chuue i) = 4;

ELSE IF (* (chuue i) == 43) * (chuue i) = 62;

ELSE IF (* (chuue i) == 47) * (chuue i) = 63;

ELSE IF (* (chuue i) == 61) * (chuue i) = 0;

For (i = 0; i <3; i )

{* (ChHEX I) = * (chuue i) << k;

K = 2;

T = * (chuue i 1) >> 8-K;

* (ChHEX I) | = T;

}

}

转载请注明原文地址:https://www.9cbs.com/read-1242.html

New Post(0)