📄 decodebase64unit.pas
字号:
//unit DecodeBase64Unit;
//interface
//implementation
function DecodeBase64_Char2Byte(org:Char):Byte;
begin
Result := 255;
case org of
'A': Result := 0;
'B': Result := 1;
'C': Result := 2;
'D': Result := 3;
'E': Result := 4;
'F': Result := 5;
'G': Result := 6;
'H': Result := 7;
'I': Result := 8;
'J': Result := 9;
'K': Result := 10;
'L': Result := 11;
'M': Result := 12;
'N': Result := 13;
'O': Result := 14;
'P': Result := 15;
'Q': Result := 16;
'R': Result := 17;
'S': Result := 18;
'T': Result := 19;
'U': Result := 20;
'V': Result := 21;
'W': Result := 22;
'X': Result := 23;
'Y': Result := 24;
'Z': Result := 25;
'a': Result := 26;
'b': Result := 27;
'c': Result := 28;
'd': Result := 29;
'e': Result := 30;
'f': Result := 31;
'g': Result := 32;
'h': Result := 33;
'i': Result := 34;
'j': Result := 35;
'k': Result := 36;
'l': Result := 37;
'm': Result := 38;
'n': Result := 39;
'o': Result := 40;
'p': Result := 41;
'q': Result := 42;
'r': Result := 43;
's': Result := 44;
't': Result := 45;
'u': Result := 46;
'v': Result := 47;
'w': Result := 48;
'x': Result := 49;
'y': Result := 50;
'z': Result := 51;
'0': Result := 52;
'1': Result := 53;
'2': Result := 54;
'3': Result := 55;
'4': Result := 56;
'5': Result := 57;
'6': Result := 58;
'7': Result := 59;
'8': Result := 60;
'9': Result := 61;
'+': Result := 62;
'/': Result := 63;
'=': Result := 64;
end;
end;
function DecodeBase64_Sub(substr:string):string;
var
te :Byte;
re :array[0..2] of Byte;
co :array[0..3] of Byte;
i:integer;
rec:string;
begin
rec := ' ';
for i := 1 to 4 do
begin
co[i-1] := DecodeBase64_Char2Byte(substr[i]);
end;
re[0] := co[0] shl 2;
te := Byte(co[1] and $30);
re[0] := Byte(re[0] or (te shr 4));
re[1] := co[1] shl 4;
te := Byte(co[2] and $3c);
re[1] := Byte(re[1] or (te shr 2));
re[2] := co[2] shl 6;
re[2] := Byte(re[2] or (co[3] and $3f));
for i:= 0 to 2 do
begin
rec[i+1] := Char(re[i]);
end;
Result := string(rec);
end;
function DecodeBase64(org:string):string;
var
ter:string;
i:integer;
len:integer;
substr:string;
size:integer;
begin
ter := '';
substr := ' ';
len := Length(org);
size := 1;
for i := 1 to len do
begin
substr[size] := org[i];
Inc(size);
if size > 4 then
begin
ter := ter + DecodeBase64_Sub(substr);
size := 1;
end;
end;
Result := ter;
end;
//end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -