📄 +
字号:
function EncodeA(pIn:PChar;pOut:PChar;Size:Integer):Integer;
var
iptr,optr,i : Integer;
b1,bcal,bflag1,bflag2 : byte;
key1,key2 : byte;
begin
iptr:=0;
optr:=0;
i:=0;
b1:=0;
bcal:=0;
bflag1:=0;
bflag2:=0;
key1:=$ac;
key2:=$3c;
while iptr<Size do
begin
b1:=byte(pIn[iptr]) xor key1;
Inc(iptr);
if i<2 then
begin
bcal:=b1;
bcal:=bcal shr 2;
bflag1:=bcal;
bcal:=bcal and $3c;
b1:=b1 and $3;
bcal:=bcal or b1;
bcal:=bcal+key2;
pOut[optr]:=chr(bcal);
Inc(optr);
bflag2:=(bflag1 and $3) or (bflag2 shl 2);
end
else
begin
bcal:=b1;
bcal:=bcal and $3f;
bcal:=bcal+key2;
pOut[optr]:=chr(bcal);
Inc(optr);
b1:=b1 shr 2;
b1:=b1 and $30;
b1:=b1 or bflag2;
b1:=b1+key2;
pOut[optr]:=chr(b1);
Inc(optr);
bflag2:=0;
end;
Inc(i);
i:=i mod 3;
end;
//下面是零头处理
if i=0 then //不是零头则返回。
begin
//pOut[optr]:=#0;
EncodeA:=1;
exit;
end;
pOut[optr]:=chr(bflag2+key2);
Inc(optr);
//pOut[optr]:=#0;
EncodeA:=optr;
end;
function DecodeA(pIn:PChar;pOut:PChar;Size:Integer):Integer;
var
i1,i2,i3,i4:byte;
i,iptr,optr:integer;
key1,key2:byte;
begin
key1:=$ac;
key2:=$3c;
iptr:=0;
optr:=0;
for i:=0 to (Size div 4)-1 do
begin
//依次取出4个字符
i1:=byte(pIn[iptr])-key2;
Inc(iptr);
i2:=byte(pIn[iptr])-key2;
Inc(iptr);
i3:=byte(pIn[iptr])-key2;
Inc(iptr);
i4:=byte(pIn[iptr])-key2;
Inc(iptr);
//生成第一个明文字符
pOut[optr]:=chr((i1 and 3) or (((i1 and $3c) shl 2) or (i4 and $c)) xor key1);
Inc(optr);
//生成第二个明文字符
pOut[optr]:=chr((i2 and 3) or (((i2 and $3c) shl 2) or ((i4 and $3)) shl 2) xor key1);
Inc(optr);
//生成第三个明文字符
pOut[optr]:=chr((i3 and $3f) or ((i4 and $30) shl 2) xor key1);
Inc(optr);
end;
case (Size mod 4) of
//当密文有2个零头字符的处理
2:begin
//分别取出零头的2个字符
i1:=byte(pIn[iptr])-key2;
Inc(iptr);
i2:=byte(pIn[iptr])-key2;
Inc(iptr);
//生成零头明文字符
pOut[optr]:=chr((i1 and 3) or ((i1 and $3c) shl 2) or ((i2 and 3) shl 2) xor key1);
Inc(optr);
end;
//当密文有3个零头字符的处理
3:begin
//分别取出零头的3个字符
i1:=byte(pIn[iptr])-key2;
Inc(iptr);
i2:=byte(pIn[iptr])-key2;
Inc(iptr);
i3:=byte(pIn[iptr])-key2;
Inc(iptr);
//生成两个零头明文字符
pOut[optr]:=chr((i1 and 3) or ((i1 and $3c) shl 2) or (i3 and $0C) xor key1);
inc(optr);
pOut[optr]:=chr((i2 and 3) or ((i2 and $3c) shl 2) or ((i3 and $03) shl 2) xor key1);
Inc(optr);
end;
end;//case结束 ;
pOut[optr]:=#0;
DecodeA:=optr;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -