求高手把DELPHI加解密代码转换成C#的,可能类似BASE64
求助把DELPHI加解密代码转换成C#的,可能类似BASE64DELPHI代码如下:
const gamestr : array [0..127] of byte =
($4E, $3E, $54, $53, $56, $55, $4A, $6C, $77, $64, $63, $42, $4D, $46, $6A, $6E, $41, $4B, $62, $3F, $71, $78, $76, $79, $65, $47, $7A, $66, $4C, $50, $3D, $5F, $45, $52, $40, $5A, $5C, $61, $6D, $5D, $43, $68, $67, $6F, $57, $44, $3B, $51, $75, $58, $5B, $3C, $74, $6B, $70, $72, $5E, $60, $69, $49, $48, $4F, $59, $73, $2E, $33, $1E, $01, $13, $22, $10, $0B, $28, $2D, $20, $0D, $19, $3C, $3B, $06, $11, $1C, $0C, $00, $3D, $1D, $2F, $21, $03, $02, $05, $04, $2C, $31, $3E, $23, $32, $24, $27, $38, $1F, $39, $25, $12, $0A, $09, $18, $1B, $2A, $29, $3A, $0E, $35, $07, $26, $0F, $2B, $36, $14, $37, $3F, $34, $30, $16, $08, $15, $17, $1A); //密钥
function decode (inchar:pchar; len:integer ; outchar:pchar):integer; //解密
function encode (inchar:pchar; len:integer ; outchar:pchar):integer; //加密
function chartoascii(str:PChar;strlen:Integer):string;
var
Form1: TForm1;
implementation
{$R *.dfm}
function decode (inchar:pchar; len:integer ; outchar:pchar):integer; //解密
var
a1, d1: byte;
i, count, di, si :integer;
begin
decode := len div 4 * 3 ; //返回长度。
i := 0;
while i < len do
begin
d1 := byte (inchar[i] );
if ( d1 = $3B ) or (d1 = $7A) then
begin
end;
d1 := d1 and $0FF;
d1 := gamestr [d1 + 05]; //d1 := byte ( gamestr [ 1 + d1 ] );
byte (inchar [i] ) := d1; // 根据不同的gamestr数据定义选用不现的方法
inc (i);
end;
di := 0 ;
si := 0 ;
count := len div 4 ; //循环次数
for i := 1 to count do
begin
a1 := ord ( inchar [di]); //解密数据 (取4个.转化3个)
a1 := a1 shl 2 ;
d1 := ord ( inchar [di + 1]);
d1 := d1 shr 4 ;
a1 := a1 or d1 ;
outchar[si] := chr (a1);
a1 := ord ( inchar [di + 1]);
a1 := a1 shl 4 ;
d1 := ord ( inchar [di + 2]);
d1 := d1 shr 2 ;
a1 := a1 or d1 ;
outchar[si + 1] := chr (a1);
a1 := ord ( inchar [di + 2]);
a1 := a1 shl 6 ;
d1 := ord ( inchar [di + 3]);
a1 := a1 or d1 ;
outchar[si + 2] := chr (a1);
di := di + 4 ;
si := si + 3 ;
end;
end;
function encode (inchar:pchar; len:integer ; outchar:pchar):integer; //加密
var
a1, d1 :byte;
i,count,di,si :integer;
begin
encode := len div 3 * 4 ; //返回加密后数据长度
di := 0 ;
si := 0 ;
count := len div 3; //定义循环次数
for i := 1 to count do
begin
a1 := ord ( inchar [di]); //第一次转换 取3个 输出4个
a1 := a1 shr 2 ;
outchar [si] := chr (a1);
a1 := ord (inchar[di]);
a1 := a1 and 3 ;
a1 := a1 shl 4 ;
d1 := ord (inchar[di +1]);
d1 := d1 shr 4 ;
a1 := a1 or d1 ;
outchar[si +1] := chr (a1) ;
a1 := ord ( inchar[di + 1]) ;
a1 := a1 and $0F ;
a1 := a1 shl 2 ;
d1 := ord ( inchar[di + 2]) ;
d1 := d1 shr 6 ;
a1 := a1 or d1 ;
outchar[si + 2] := chr (a1);
a1 := ord ( inchar[di + 2]) ;
a1 := a1 and $3F;
outchar[si + 3] := chr (a1) ;
//第二次转换
d1 := ord ( outchar [si]); //第 1 个
d1 := gamestr [d1];
outchar [si] := chr (d1);
d1 := ord ( outchar [si + 1]); //第 2 个
d1 := gamestr [d1];
outchar [si + 1] := chr (d1);
d1 := ord ( outchar [si + 2 ]); //第 3 个
d1 := gamestr [d1];
outchar [si + 2] := chr (d1);
d1 := ord ( outchar [si + 3]); //第 4 个
d1 := gamestr [d1];
outchar [si + 3] := chr (d1);
di := di + 3 ;
si := si + 4 ;
end;
end;
下面是密码和明文
密文:UANNNNNNNNNBNNpNAEVN>A>XyNKe
密文16进制:05 10 00 00 00 00 00 00 00 00 00 0B 00 00 36 00 10 20 04 00 01 10 01 31 17 00 11 18
解密后16进制:15 00 00 00 00 00 00 00 0B 00 0D 80 42 01 00 05 00 71 5C 04 58
求大侠们赐教~