// BaseTable is BaseTable: String = '' '' '' 'AbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrStuvwxyz0123456789 / =' '' '' ';';
Function decodeBase64 (Source: String): String; // Decoding function function findintable (csource: char): integer; // function encodebase64 (Source: string): string; // encoding function
// Function Findintable (CSource: Char): Integer; Begin Result: = POS (String (csource), BaseTable) -1; End; Function DecodeBase64 (Source: String): String; Var srclen, Times, i: integer; x1 , X2, X3, X4, XT: Byte; Begin Result: = '' '' ''; Srclen: = Length (Source); Times: = Srclen Div 4; for i: = 0 to Times-1 Do Begin x1: = findintable (Source [1 i * 4]); x2: = findintable (Source [2 i * 4]); x3: = findintable (Source [3 i * 4 ]); x4: = Findintable (Source [4 i * 4]); x1: = x1 shl 2; xt: = x2 shr 4; x1: = x1 or xi xt; x2: = x2 shl 4; Result: = Result chr (x1); if x3 = 64 THEN BREAK; XT: = x3 shr 2; x2: = x2 or xt; x3: = x3 shl 6; Result: = Result chr (x2); if x4 = 64 THEN BREAK ; x3: = x3 or x4; result: = Result chr (x3); end; end; / function encodebase64 (Source: string): string; var Times, Lensrc, i: integer; x1, x2, x3, x4: CHAR; XT: Byte; Begin Result: = '' '' '' '' '' '' '; Lensrc: = Length (Source); if Lensrc MOD 3 = 0 THEN TIMES: = Lensrc Div 3 else Times : = Lensrc Div 3 1; for i: = 0 to Times-1 Do Begin if Lensrc> = (3 i * 3) Then Begin x1: = BaseTable [(ORD (Source [1 i * 3]) SHR 2) 1]; XT: = (ORD (Source [1 I * 3]) SHL 4) and 48; XT: = XT OR (ORD (Source [2 I * 3]) SHR 4); x2: = baseteable [ XT 1]; XT: = (ORD (Source [2 I * 3]) SHL 2) and 60; XT: = XT OR (ORD (Source [3 I * 3]) SHR 6); x3: = BaseTable [XT 1]; XT: = (ORD (Source [3 I * 3]) and 63); x4: = basetable [xt 1]; ELSE IF LENSRC> = (2 i * 3) THEN Begin x1: = basetable [(Source [1 I * 3]) SHR 2) 1]; XT: = (ORD (Source [1
I * 3]) SHL 4) and 48; XT: = XT OR (ORD (Source [2 i * 3]) SHR 4); x2: = basetable [xt 1]; XT: = (ORD (Source [ 2 i * 3]) SHL 2) and 60; x3: = baseteable [xt 1]; x4: = '' '' '' '=' '' '' ''; end else begin x1: = BaseTable [(Source [1 I * 3]) SHR 2) 1]; XT: = (ORD (Source [1 I * 3]) SHL 4) and 48; x2: = baseteable [xt 1 ]; x3: = '' '' '' '' '' '' ''; x4: = '' '' '' '=' '' '' ''; end; result: = Result X1 X2 X3 X4; END; END; // /// GB2312 Content Decoding Function TFORM1.EncodeChinese (VAR INPUTSTR: STRING): String; // Get Unicode Code CP936 (you can also Get unicode encoding) VAR I, J, LEN, CUR: Integer; T: String; WS: WIDESTRING; // Note This begin result: = ''; ws: = inputstr; // Note This LEN : = Length (WS); // Change to LEN: = Length (InputStr) i: = 1; // j: = 0; While i <= len do begin cur: = ORD (WS [i]); /// Change to Cur: = ORD (INPUTSTR [I]) FMTSTR (T, '% 4.4x', [CUR]); Result: = Result T; // After the modification of the above comments, UNCODE encoding INC (I ); // j: = (j 1) MOD 7; end;
Function TForm1.DecodeChinese (VAR INPUTSTR: STRING): String; // converts the code page for the Unicode encoding of the CP936 into GB2312 Chinese code VAR I, LEN, J: Integer; T: string; begin result: = '; LEN : = Length (InputStr); i: = 1; while i <= len do beg: = copy (inputstr, i, 4); J: = STRTOINT ('$' T); T: = Widechar (j) Result: = Result T; i: = i 4; end; end;