I believe that friends who have been online have met "garbled", which is the unrecognizable characters that appear when browsing the web or seeing email. There have been many articles in the past, "garbled", but their articles just spend how to distinguish and use tool decoding, and have not detailed the implementation of the algorithms of various codes, this article will be the most commonly used coding coding on the Internet. The decoding algorithm is elaborated in detail. I hope to have some reference value for those who want to understand the "garble" algorithm or want to implement these functions in their own programs. The source program of this article writes in C language, forms a function, can be used directly.
Uuencode:
UUENCODE is to encode the binary in a text file method to facilitate one of the coding methods of transfer / exchange in a text transport environment. It is relatively high in the mail system / binary news group. It is often used for Attach. binary file.
This feature of this coding is: Each line starts with the "M" flag. Here is the file mogao.txt I have made, encoded as uuencode:
Begin 644 mogao.txt
M "0D) (" `@ (* & vpm " z / ocmzbt // bkh; <- "@g7]] 7? .Fuo9v% ohzrpu] 3 & n /: z
MU] 6 ^ hzat96qn970z R / R, # (N, 3 $ R C (p c $ s, chr, z.il / g4l: & C # 0H) ("` @
M ("` @ q * jxw / cmo / zyi-? WRM * cnfat = '`z r] m; v = a; ryb96yt: 75n fye =` t *
M "0D) 16ua: 6qt; sim; v = a; t`s-s $ n; F5T # 0H) (" `@ * bhj * bhj * bhj * bhj * bhj
M * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ ("` @ ("` @ ("` @ ("` @ ("` @
M # 0H) ("` @ * b "s _ <' O,? 2Y, JRP [2VO * [M / C7WZ.LL_W! R]? CO * / * LL.TMKRR
Mn / 'TS / (J # 0H) ("` @ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ * BHJ
* BHJ * BHJ * BHJ * BHJ
`
end
You can separate it separate into a file: Mogao.uue, then open with Winzip, decompress Mogao.txt.
UUENCODE algorithm is simple, it is encoded which put three characters in the order of 24-bit buffers, and makes up the fault to make up the buffer to become 4 parts, the high is in the first, 6 bits per part, Re-represented by 64 characters below:
"`! "# $% & '() * , -. / 0123456789:; <=>? @ AbcdefghijklmnopqrStuvwxyz [/] ^ _"
In the beginning of the file, "Begin XXX encoded file name", with "end" at the end of the file, used to log the beginning and end of the UUE file. When encoding, each time you read the 45 characters of the source file, less than 45 "NULL" make up the integer multiple of 3 (such as: 23), then enter the target file an ASCII as: "32 actual reading The character of the character is taken as the beginning of each line. After reading the character encoded, enter the destination file, then enter a "wrap". If the source file is encoded, then "` (ASCII is 96) "and a" wrap "indicates the end of the encoding. When decoding it converts 4 characters to 4 6-digit characters respectively, take a 24-bit buffer, which is 3 binary code.
Here I gave UUENCODE encoding and decoding C language description:
/ * Uuencode encoding * /
Void Uue (unsigned char chasc [3], unsigned char chuue [4])
/ *
CHASC: Uncoded binary code
Chuue: Coded UUE code
* /
{INT I, K = 2;
UNSIGNED Char t = NULL;
For (i = 0; i <3; i )
{* (chuue i) = * (chasc i) >> K;
* (chuue i) | = t;
IF (* (chuue i) == null) * (chuue i) = 96;
ELSE * (Chuue i) = 32;
T = * (chasc i) << (8-k);
T >> = 2;
K = 2;
}
* (chuue 3) = * (chasc 2) & 63;
IF (* (chuue 3) == null) * (chuue 3) = 96;
ELSE * (Chuue 3) = 32;
}
/ * Uuencode decoding * /
Void unuue (unsigned char chuue [4], unsigned char chasc [3])
/ *
Chuue: UUE code unresolved
CHASC: Decoded binary code
* /
{INT I, K = 2;
UNSIGNED Char t = NULL;
IF (* chuue == 96) * chuue = NULL;
Else * chuue- = 32;
For (i = 0; i <3; i )
{* (chasc i) = * (chuue i) << k;
K = 2;
IF (* (chuue i 1) == 96) * (Chuue i 1) = null;
ELSE * (Chuue i 1) - = 32;
T = * (chuue i 1) >> 8-K;
* (chasc i) | = T;
}
}