3 (*
\82©
\82È
\82è
\83C
\83\93\83`
\83L
\81\95\8cø
\97¦
\88«
\82¢
\81\95\90^
\96Ê
\96Ú
\82É
\8c\9f\8fØ
\82µ
\82Ä
\82È
\82¢ *)
10 procedure HogeBase64Encode(inputStream, outputStream: TStream); overload;
11 procedure HogeBase64Decode(inputStream, outputStream: TStream); overload;
13 function HogeBase64Encode(const inputStr: string): string; overload;
14 function HogeBase64Decode(const inputStr: string): string; overload;
19 Enc64Tbl: array[0..63] of Char =
20 ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
21 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
22 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
23 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/');
25 (*
\83f
\83R
\81[
\83h
\83e
\81[
\83u
\83\8b \83\81\83\93\83h
\83C *)
27 procedure HogeBase64Encode(inputStream, outputStream: TStream);
29 inBuf: array [0..2] of byte;
30 outBuf: array[0..3] of Char;
34 size := inputStream.Read(inBuf, sizeof(inBuf));
39 outBuf[0] := Enc64Tbl[inBuf[0] shr 2];
40 outBuf[1] := Enc64Tbl[(inBuf[0] shl 4) and $3F];
46 outBuf[0] := Enc64Tbl[inBuf[0] shr 2];
47 outBuf[1] := Enc64Tbl[((inBuf[0] shl 4) or (inBuf[1] shr 4)) and $3F];
48 outBuf[2] := Enc64Tbl[((inBuf[1] shl 2) ) and $3F];
53 outBuf[0] := Enc64Tbl[inBuf[0] shr 2];
54 outBuf[1] := Enc64Tbl[((inBuf[0] shl 4) or (inBuf[1] shr 4)) and $3F];
55 outBuf[2] := Enc64Tbl[((inBuf[1] shl 2) or (inBuf[2] shr 6)) and $3F];
56 outBuf[3] := Enc64Tbl[inBuf[2] and $3F];
59 outputStream.WriteBuffer(outBuf, sizeof(outBuf));
60 until size < sizeof(inBuf);
63 procedure HogeBase64Decode(inputStream, outputStream: TStream);
65 inBuf: array [0..3] of Char;
66 outBuf: array[0..2] of byte;
73 size := inputStream.Read(inBuf, sizeof(inBuf));
77 raise EConvertError.Create('unexpected size');
78 for i := 0 to sizeof(outBuf) -1 do
81 for i := 0 to sizeof(inBuf) - 1 do
84 'A'..'Z': code := Ord(inBuf[i]) - Ord('A');
85 'a'..'z': code := Ord(inBuf[i]) - Ord('a') + 26;
86 '0'..'9': code := Ord(inBuf[i]) - Ord('0') + 26 + 26;
92 raise EConvertError.Create('unexpected "="');
97 raise EConvertError.Create(Format('unexpected code($%2.2X)', [Ord(inBuf[i])]));
102 outBuf[0] := code shl 2;
106 outBuf[0] := outBuf[0] or (code shr 4);
107 outBuf[1] := code shl 4;
111 outBuf[1] := outBuf[1] or (code shr 2);
112 outBuf[2] := code shl 6;
116 outBuf[2] := outBuf[2] or code;
121 endPos := sizeof(outBuf);
122 outputStream.WriteBuffer(outBuf, endPos);
123 until size < sizeof(inBuf);
127 function HogeBase64Encode(const inputStr: string): string; overload;
129 inputStream, outputStream: TStringStream;
131 inputStream := TStringStream.Create(inputStr);
132 outputStream:= TStringStream.Create('');
133 HogeBase64Encode(inputStream, outputStream);
134 result := outputStream.DataString;
139 function HogeBase64Decode(const inputStr: string): string; overload;
141 inputStream, outputStream: TStringStream;
143 inputStream := TStringStream.Create(inputStr);
144 outputStream:= TStringStream.Create('');
145 HogeBase64Decode(inputStream, outputStream);
146 result := outputStream.DataString;