delphi Base24编码解码


本文整理自网络,侵删。

 
unit Base24Unt;

{Base24}

interface

const
  EncodeTable: array[0..23] of Char ='BCDFGHJKMPQRTVWXY2346789' ;

  DecodeTable: array[#0..#127] of Byte = (
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,17,18,19,25,20,21,
    22,23,25,25,25,25,25,25,
    25,25, 0, 1, 2,25, 3, 4,
     5,25, 6, 7,25, 8,25,25,
     9,10,11,25,12,25,13,14,
    15,16,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25,
    25,25,25,25,25,25,25,25);

function ByteToBase24(buf:array of byte):String;
function FormatBase24(sValue:String;Const bAdd:Boolean=False):String;
procedure Base24ToByte(sValue:String;var buf:array of byte);


implementation

function ByteToBase24(buf:array of byte):String;
var
  i,j:Integer;
  K:Longword;
begin
  for i := 24 downto 0 do
    begin
    K := 0;
    for j := High(buf) downto Low(buf) do
      begin
      K := (K * 256) + buf[j];
      buf[j] := K div 24;
      K := K mod 24;
      end;
    Result :=ConCat(EncodeTable[K],Result);
    end;
end;

procedure Base24ToByte(sValue:String;var buf:array of byte);
var
  i,j:Integer;
  K:Longword;
begin
  for i:=0 to 24 do
    begin
    k:=DecodeTable[sValue[i+1]];
    for j:=0 to 14 do
      begin
      K:=buf[j]*24+K;
      buf[j]:=K mod 256;
      k:=K div 256;
      end;
    end;
end;

function FormatBase24(sValue:String;Const bAdd:Boolean=False):String;
var
  i,n:Integer;
begin
Result:='';
n:=Length(sValue);
for i:=1 to n do
  begin
  if bAdd then
    begin
    if (i mod 5=0)and(i<>n) then
      begin
      Result:=ConCat(Result,sValue[i],'-');
      continue;
      end;
    end else begin
    if sValue[i]='-' then continue;
    end;
  Result:=ConCat(Result,sValue[i]);
  end;

end;

end.

相关阅读 >>

Delphi 立即停止timer

Delphi & c++ 安卓使用权限

Delphi twebbrowser也能响应回车键

Delphi 提取网页源文件纯文本函数

Delphi中将webbrowser用作网页编辑器

Delphi png 图片的十六进制字符流

Delphi 如何把类中的方法做参数

Delphi tfdquery提交tfdmemtable修改的数据

Delphi program name、process id、window handle、process handle 的转换函数

Delphi datasnap 的http 调用返回json

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...