...encode / decode Base64 string?
http://www.swissdelphicenter.ch/torry/showcode.php?id=1524
onst
Codes64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/';
function Encode64(S: string): string;
var
i: Integer;
a: Integer;
x: Integer;
b: Integer;
begin
Result := '';
a := 0;
b := 0;
for i := 1 to Length(s) do
begin
x := Ord(s[i]);
b := b * 256 + x;
a := a + 8;
while a >= 6 do
begin
a := a - 6;
x := b div (1 shl a);
b := b mod (1 shl a);
Result := Result + Codes64[x + 1];
end;
end;
if a > 0 then
begin
x := b shl (6 - a);
Result := Result + Codes64[x + 1];
end;
end;
function Decode64(S: string): string;
var
i: Integer;
a: Integer;
x: Integer;
b: Integer;
begin
Result := '';
a := 0;
b := 0;
for i := 1 to Length(s) do
begin
x := Pos(s[i], codes64) - 1;
if x >= 0 then
begin
b := b * 64 + x;
a := a + 6;
if a >= 8 then
begin
a := a - 8;
x := b shr a;
b := b mod (1 shl a);
x := x mod 256;
Result := Result + chr(x);
end;
end
else
Exit;
end;
end;
'program' 카테고리의 다른 글
[Android] Make sure to call FirebaseApp.initializeApp(Context) first (0) | 2019.03.29 |
---|---|
opencv (0) | 2016.07.13 |
xml mapper 사용 (0) | 2016.02.05 |
엑셀 색상(Columns.Interior.ColorIndex) (0) | 2016.01.22 |
랜카드 물리적 주소 가져오기(jvcl 다운로드링크) (0) | 2016.01.20 |