rc_codecs.pas

来自「Rijndael algorithm修正了CBC下BUG的版本(有源代码)工作在」· PAS 代码 · 共 55 行

PAS
55
字号
unit rc_codecs;

interface

uses sysutils;

function rc_Decode(sCoded: string): string;
function rc_Encode(sString: string): string;

implementation

function rc_Decode(sCoded: string): string;
var
  i,j,c: integer;
  sRes: string;
begin
  sRes:= '';
  i:= 1;
  j:= length(sCoded);
  while i<= j do
    begin
      if ((sCoded[i]= '%') and ((j-i)>1)) then
         try
           c:= strtoint('$'+copy(sCoded,i+1,2));
           sRes:= sRes+ chr(c);
           i:= i+ 2;
         except
           sRes:= sRes+ sCoded[i];
         end
      else
        sRes:= sRes+ sCoded[i];
      inc(i);
    end;
  result:= sRes;
end;

function rc_Encode(sString: string): string;
var
  i,j: integer;
  sRes: string;
begin
  sRes:= '';
  j:= length(sString);
  for i:= 1 to j do
    if ((sString[i]= '*') or (sString[i]= '-') or (sString[i]= '.') or (sString[i]= '_') or (sString[i]= '@')
          or ((sString[i]>= 'A') and (sString[i]<= 'Z')) or ((sString[i]>= 'a') and (sString[i]<= 'z'))
          or ((sString[i]>= '0') and (sString[i]<= '9'))) then
      sRes:= sRes+ sString[i]
    else
      sRes:= sRes+ format('%%%.2X',[ord(sString[i])]);
  result:= sRes;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?