Mail format encoding and decoding

xiaoxiao2021-03-06  50

INT Encodequoted (const unsigned char * psrc, char * pdst, int nsrclen, int ndstlen; // output character count INT nLinelen; // output line length count NDstlen = 0; nLinelen = 0; for (int i = 0; i = '!') && (* psrc <= '~' ) && (* psrc! = '=')) {* PDST = (char) * psrc; ndstlen ; nLinelen ;} else {sprintf (pdst, "=% 02x", * psrc); PDST = 3; NDstlen = 3; nLinelen = 3;} // Output wrap? IF (nLinelen> = NmaxLinelen - 3) {sprintf (pdst, "= / r / n"); PDST = 3; ndstlen = 3; nLinelen = 0;}} // output add a end value * PDST = ' / 0 '; return ndstlen;}

Quoted-printable decoding is very simple, it will be in turn of the encoding process.

INT decodequoted (const char * psrc, unsigned char * pdst, int nsrclen) {int ndstlen; // output character count INT i; i = 0; ndstlen = 0; While (I

While ((hz = * finputtext )! = '/ 0') {if (hz> = 161) {if (! x) {* (foutPutText i) = '~'; i ; * (foutPutText i) = '{'; I ; x = 1;} else x = 1; * (foutPutText i) = (char) (HZ-128); i ;} else {if (x) {* (foutPutText i) = ' ~ '; I ; * (FoutPutText i) ='} '; i ; x = 0;} else x = 0; * (foutPutText i) = Hz; i ;}} if (x) {* (foutputText I) = '~'; i ; * (foutPutText i) = '}'; i ; x = 0;} * (foutPutText i) = '/ 0'; foutput = (ANSISUTRING) foutPutText;}

/ / -------------------------------------------------------------------------------------------- -------------------------- // Decode the HZ VOID __fastcall decodehz (void) {unsigned i = 0; unsigned char Hz; while ((hz = * finputtext )! = '/ 0') {loop2: if (hz == 126) IF ((hz = * finputText )! = '/ 0') if (hz == 123) While ((Hz = * FinputText )! = '/ 0') {loop3: if (hz == 126) {IF ((hz = * finputtext )! = '/ 0') IF (Hz == 125) goto loop; else {* (FoutPutText I) = (char) 254; i ; goto loop3;}} else {* (foutPutText i) = (char) (HZ 128); i ;}} else {* (foutputText i) = ' ~ '; i ; goto loop2;} else {* (foutPutText i) =' ~ '; i ; goto end;} else {* (foutPutText i) = Hz; i ;} loop :;} end :; * (FoutPutText i) = '/ 0'; foutput = (ANSISUTRING) foutputtext;} // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------- // use QP Code void __fastcall encodeqp (void) {UNSIGNED CHAR FIRST, SECOND, SOUR; UNS IGNED INT i = 0; while ((SOUR = * FinputText )! = '/ 0') {IF (Sour == 61) {* (FoutPutText i) = '='; i ; * (foutPutText i) = '3'; i ; * (foutPutText i) = 'd'; i ;} else {if (SOUR> 127) {first = SOUR >> 4; second = source & 15; if (first> 9) first = 55; Else first = 48;

IF (Second> 9) Second = 55; Else Second = 48; * (FoutPutText i) = '='; i ; * (foutPutText i) = first; i ; * (foutPutText i) = second; i ; } Else {* (foutPutText i) = Sour; i ;}}} * (foutPutText i) = '/ 0'; foutput = (ANSISTRING) foutPutText;} // ----------- -------------------------------------------------- -------------- // Decoding the QP __fastcall decodeqp (void) {Unsign CHAR FIRST, SECOND, SOUR; unsigned Int i = 0; while ((Sour = * FinputText )! = '/ 0') {IF (SOUR == 61) {IF ((first = * finputText ) == '/ 0') {* (foutPutText i) = SOUR; I ; Break;} else f ((First <48) || ((First> 57) && (First> 70)) {* (FoutPutText i) = SOUR; i ; * (FoutPutText i) = first; i ; Continue } Else if (second = * finputtext ) == '/ 0') {* (foutPutText i) = SOUR; I ; * (foutPutText i) = first; i ; break;} else f ((Second < 48) || ((SECO) ND> 57) && (Second <65)) || (Second> 70)) {* (FoutPutText i) = SOUR; i ; * (FoutPutText i) = first; i ; * (foutPutText i) = second I ; continuous;}

IF (first> = 65) first- = 55; else first- = 48; if (second> = 65) second- = 55; else second- = 48; Sour = null; Sour = first << 4; Sour | = SECOND;} * (FoutPutText i) = SOUR; i ;} * (foutPutText i) = '/ 0'; foutput = (ANSISTRING) foutPutText;} // ------------- -------------------------------------------------- ------------ // Code void __fastcall encodebase64 (void) {unsigned char * sour, * Obje, * inputText; unsigned int i, j = 0, m = 57, n = 57; InputText = FinputText; Sour = new char [57]; Obje = new char [76]; while (m == 57) {m = strlen (inputText); if (m <57) {ix (m == 0 Break; n = m; strncpy (Sour, INPUTTEXT, M); if (n% 3) n = nn% 3 3; for (i = m; 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;} // --------- -------------------------------------------------- ---------------- // VOID __FASTCALL DECODEBASE64 (Void) {Unsigned Char * Sour, * Obje, * InputText; Unsigned Int I, J = 0, M = 57 , n = 76; source = new char [76]; inputText = FinputText; while (m == 57) {while (* inputtext == '/ r' || * inputText == ' / N ') InputText ; M = Strlen (InputText); if (M <76) {if (m == 0) Break; n = m;} m = N / 4 * 3;

STRNCPY (SOUR, INPUTTEXT, N); InputText = N; for (i = 0; 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 ) {* (chasc i) = * (chuue i) << k; k = 2; t = * (chuue i 1) >> 8-k; * (chasc i) | = t;}} // ------------------------------------ --------------------------------------- // Code void __fastcall encodeuue with uuencode (Void ) {Unsigned char * SOUR, * Obje, * inputtext; unsigned INT i, j = 0, m = 45, n = 45, Num; inputText = FinputText; source = new char [45]; Obje = new char [60] WHILE (M == 45) {m = strlen (InputText); if (M <45) {if (m == 0) Break; n = m; STRNCPY (SOUR, INPUTTEXT, M); IF (N% 3 ) n = nn% 3 3; for (i = m; 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;} // ----------- -------------------------------------------------- -------------- // Decoded Void __fastcall decodeuue (void) {unsigned char * SOUR, * Obje, * inputText; unsigned int i, j = 0, m = 45, N ; Sour = new char [60]; objectText = FinputText; While (M == 45) {while (* inputtext == '/ r' || * inputText == '/ n') InputText ; if ((m = * inputtext)! = 96 || m == '/ 0') {n = m-32; m = n; inputText ;} else break; if (n <45) {ix % 3) n = (n% 3 3) / 3 * 4; ELSE N = N / 3 * 4;} else n = N / 3 * 4; STRNCPY (SOUR, INPUTTEXT, N); InputText = n; for (i = 0; i

1) = NULL; ELSE * (Chuue i 1) - = 32; t = * (chuue i 1) >> 8-k; * (chasc i) | = t;}} // -------------------------------------------------- ----------------------- // Code void __fastcall encodexxe (void) {unsigned char * SOUR, * OBJE, * InputText; unsigned int i , j = 0, m = 45, n = 45; char set [] = " - 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; inputtext = FInputText; sour = new char [45]; obje = new char [60]; while (m == 45 ) {M = strlen (INPUTTEXT); if (m == 0) Break; n = m; STRNCPY (SOUR, INPUTTEXT, M); if (n% 3) n = n% 3 3; for (i = m; i > 2; chxxe [1] = (chasc [0] << 4) &

48 | (Chasc [1] >> 4) & 15; chxxe [2] = (Chasc [1] << 2) & 60 | (Chasc [2] >> 6) & 3; chxxe [3] = Chasc [2] & 63 ; For (i = 0; i <4; i ) chxxe [i] = set [chxxe [i]]; / * Chart * /} / * Tell, the first part of the XXencode file part of each line The letter is: After the number of ASCII values ​​obtained from the actual number of characters actually read in the source file, the SET [] checksum is obtained. * /

/ / -------------------------------------------------------------------------------------------- --------------------------- // For xxencode decoded void __fastcall decodexxe (void) {unsigned char * SOUR, * Obje, * inputText; Unsigned INT I, J = 0, M = 45, N; SOUR = New Char [60]; Obje = New Char [45]; InputText = FinputText; While (M == 45) {While (* InputText == '/ R '|| * inputText ==' / n ') InputText ; if ((m = * inputtext)! =' '|| m ==' / 0 ') {n = set (m); m = n; InputText ;} else break; if (n <45) {if (n% 3) n = (n% 3 3) / 3 * 4; ELSE N = N / 3 * 4;} else n = n / 3 * 4; STRNCPY (SOUR, INPUTTEXT, N); InputText = N; for (i = 0; i = 48 && Ch <= 57) CH- = 46; ELSE IF (CH> = 65 && Ch <= 90) CH- = 53; ELSE IF (CH> = 97 && Ch <= 122) CH- = 59; Return ch;} // -------------------------------------------- ------------------------------- void __fastcall unxxe (unsigned char chas [4], unsigned char chasc [3]) / * chXXE: Unresolved XXE code chasc: Decoded binary code * / {INT K = 2, i; unsigned char t; t = null; * chxxe = set (* chxxe); for (i = 0; i < 3; i

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

New Post(0)