|
const tblB64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; |
|
function EnB64(const s: string): string; function DeB64(const sB64: string): string; |
function EnB64(const s: string): string;
var
sB64: string;
pos4, bit, i: Byte;
l, n: integer;
bc: array[1..4] of Byte;
begin
sB64:='';
l:=Length(s);
pos4:=1;
n:=1;
while n<=l do begin
bit:=ord(s[n]);
case pos4 of
1: begin
bc[1]:=bit shr 2;
bc[2]:=(bit and $03) shl 4;
if n=l then for i:=1 to 2 do sB64:=sB64 + Copy(tblB64,bc[i]+1,1);
end;
2: begin
bc[2]:=bc[2] or (bit shr 4);
bc[3]:=(bit and $0F) shl 2;
if n=l then for i:=1 to 3 do sB64:=sB64 + Copy(tblB64,bc[i]+1,1);
end;
3: begin
bc[3]:=bc[3] or (bit shr 6);
bc[4]:=bit and $3F;
for i:=1 to 4 do begin
sB64:=sB64 + Copy(tblB64,bc[i]+1,1);
bc[i]:=0;
end;
pos4:=0;
end;
end;
inc(n);
inc(pos4);
end;
Result:=sB64;
if (Length(sB64) mod 4)<>0 then
Result:=Result + StringOfChar('=', 4-(Length(sB64) mod 4));
end;
//-----------------------------------------------------------------
function DeB64(const sB64: string): string;
var
s: string;
pos4, bit: Byte;
l, n: integer;
bc: array[1..3] of Byte;
begin
s:='';
l:=Length(sB64);
pos4:=1;
n:=1;
while n<=l do begin
bit:=Pos(sB64[n],tblB64)-1;
if bit=64 then begin
if bc[pos4-1]<>0 then s:=s + Chr(bc[pos4-1]);
Break;
end;
case pos4 of
1: bc[1]:=bit shl 2;
2: begin
bc[1]:=bc[1] or ((bit and $30) shr 4);
s:=s + Chr(bc[1]);
bc[2]:=(bit and $0F) shl 4;
end;
3: begin
bc[2]:=bc[2] or ((bit and $3C) shr 2);
s:=s + Chr(bc[2]);
bc[3]:=(bit and $03) shl 6;
end;
4: begin
bc[3]:=bc[3] or (bit and $3F);
s:=s + Chr(bc[3]);
pos4:=0;
end;
end;
inc(pos4);
inc(n);
end;
Result:=s;
end;
|
|
セット内容( 190KB ): ・手抜きソースファイル(コメント無し!!) ・手抜きコンパイル済み実行ファイル |