一个异或加密解密函数

网上有很多这种加密解密函数,都差不多,整理两个,以后方便使用。

const {常量}
  XorKey: array[0..7] of Byte = ($B2, $11, $AB, $35, $63, $6D, $48, {1}9); //字符串加密用,可以自己改
//两种差不多,使用重载。
function EncStrX(ASource: pansichar): string; overload; //加密
function DecStrX(ASource: pansichar): string; overload; //解密
function EncStrX(ASource: string): string; overload; //加密
function DecStrX(ASource: string): string; overload; //解密


 

function EncStrX(ASource: pansichar): string; //加密
var
  j: Integer;
  cTemp: Char;
  str, sResult: string;
begin
  j := 0;
  str := string(ASource);
  for cTemp in str do
  begin
    sResult := sResult + IntToHex(Byte(cTemp) xor XorKey[j], 2);
    j := (j + 1) mod 8; //取余
  end;
  result := pchar(sResult);
end;

function DecStrX(ASource: pansichar): string; //解密
var
  i, j: Integer;
  str, sResult: string;
begin
  str := string(ASource);
  j := 0;
  for i := 1 to Length(Str) div 2 do
  begin
    sResult := sResult + Char(StrToInt('$' + Copy(Str, i * 2 - 1, 2)) xor XorKey[j]);
    j := (j + 1) mod 8;
  end;
  result := pchar(sResult);
end;

function EncStrX(ASource: string): string; //加密   這是用的一個異或加密 var   i,j:Integer; begin   Result:='';   j:=0;   for i:=1 to Length(ASource) do   begin     Result:=Result+IntToHex(Byte(ASource[i]) xor XorKey[j],2);     j:=(j+1) mod 8;   end; end;

function DecStrX(ASource: string): string; var   i,j:Integer; begin   Result:='';   j:=0;   for i:=1 to Length(ASource) div 2 do     begin       Result:=Result+Char(StrToInt('$'+Copy(ASource,i*2-1,2)) xor XorKey[j]);       j:=(j+1) mod 8;     end; end;


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值