大哥:请把这一小段C翻译成Delphi(在线等候).帮帮忙吧,怎么这么冷漠? (100分)

  • 主题发起人 DZHZH2000
  • 开始时间
D

DZHZH2000

Unregistered / Unconfirmed
GUEST, unregistred user!
如下:(这一段静态数组定义不必翻译)
const static BYTE tg_mima[256]=
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xbe, 0x84, 0xe1, 0x6c, 0xd6, 0xae, 0x52, 0x90, 0x49, 0xf1, 0xf1, 0xbb, 0xe9, 0xeb, 0xb3, 0xa6,
0xdb, 0x87, 0x0c, 0x99, 0x5e, 0x0d, 0x1c, 0x06, 0xb7, 0x47, 0xde, 0xb3, 0x12, 0x4d, 0xc8, 0x43,
0xbb, 0x8b, 0xa6, 0x1f, 0x03, 0x7d, 0x09, 0x38, 0x25, 0x1f, 0xd4, 0xcb, 0xfc, 0x96, 0xf5, 0x3b,
0x13, 0x0d, 0x89, 0x0a, 0x1c, 0xdb, 0xae, 0x32, 0x20, 0x9a, 0xee, 0x78, 0x36, 0xfd, 0x12, 0x32,
0xf6, 0x9e, 0x49, 0xdc, 0xad, 0x4f, 0x14, 0xf2, 0x44, 0x40, 0xd0, 0xc4, 0x30, 0xb7, 0x32, 0x3b,
0xa1, 0x22, 0xf6, 0x22, 0x91, 0x9d, 0xe1, 0x8b, 0x1f, 0xda, 0xb0, 0xca, 0x99, 0x02, 0xb9, 0x9d,
0x49, 0x2c, 0x7e, 0xc5, 0xd5, 0xe9, 0xb2, 0xea, 0xc9, 0xcc, 0x53, 0xbf, 0x67, 0xd6, 0xbf, 0x14,
0xd6, 0x7e, 0x2d, 0xdc, 0x66, 0xef, 0x57, 0x49, 0x61, 0xff, 0x69, 0x61, 0xcd, 0xd1, 0x1e, 0x16,
0x72, 0x72, 0xe6, 0x1d, 0xf0, 0x84, 0x4f, 0x4a, 0x77, 0x02, 0xd7, 0xe8, 0x39, 0x2c, 0x53, 0xcb,
0xc9, 0x12, 0x1e, 0x33, 0x74, 0x9e, 0x0c, 0xf4, 0xd5, 0xd4, 0x9f, 0xd4, 0x59, 0x7e, 0x35, 0xcf,
0x32, 0x22, 0xf4, 0x90, 0x2d, 0x48, 0x8f, 0x75, 0xe6, 0x1d, 0x2a, 0xe5, 0xf7, 0x2b, 0x78, 0x81,
0x87, 0x44, 0x0e, 0x5f, 0x50, 0x00, 0x61, 0x8d, 0xbe, 0x7b, 0x05, 0x15, 0x07, 0x3b, 0x33, 0x82,
0x1f, 0x18, 0x70, 0x92, 0xda, 0x64, 0x54, 0xce, 0xb1, 0x85, 0x3e, 0x69, 0x15, 0x46, 0x6a, 0x04,
0x96, 0x73, 0x0e, 0xd9, 0x16, 0x2f, 0x67, 0x68, 0xd4, 0x4a, 0x4a, 0xd0, 0x57, 0x68, 0x76, 0x16
};
以上的可以不必翻译
void Encrypt(char* pBuffer, DWORD dwBufferLength)
{
// Ëæ»úÉú³ÉÒ»¸ö´óÓÚ0x20µÄÒò×Ó
char tmpSnd[256];
BYTE m_xor=rand()%256;
DWORD pos, n;
memset(tmpSnd, '/0', 256);
if(m_xor<0x20)m_xor+=0x20;
// &amp;Atilde;&amp;Uuml;&amp;Icirc;&amp;Auml;&amp;micro;&amp;Uacute;&amp;Ograve;&amp;raquo;&amp;cedil;&amp;ouml;×&amp;Ouml;&amp;frac12;&amp;Uacute;&amp;Icirc;&amp;ordf;&amp;frac34;&amp;Oslash;&amp;Otilde;óXOR&amp;micro;&amp;Auml;&amp;AElig;&amp;eth;&amp;Ecirc;&amp;frac14;&amp;Icirc;&amp;raquo;&amp;Ouml;&amp;Atilde;
tmpSnd[0] = m_xor;
// &amp;Atilde;&amp;Uuml;&amp;Icirc;&amp;Auml;&amp;AElig;&amp;auml;&amp;Euml;&amp;ucirc;×&amp;Ouml;&amp;frac12;&amp;Uacute;&amp;Ograve;&amp;Agrave;&amp;acute;&amp;Icirc;XOR&amp;frac34;&amp;Oslash;&amp;Otilde;ó&amp;Auml;&amp;Uacute;&amp;Egrave;&amp;Yacute;
for(n=0;
n<dwBufferLength-1;
n++)
{
//&amp;frac14;&amp;AElig;&amp;Ecirc;&amp;yacute;&amp;AElig;÷&amp;Otilde;&amp;Ucirc;&amp;raquo;&amp;Oslash;&amp;Ecirc;±&amp;Ocirc;&amp;frac12;&amp;sup1;&amp;yacute;&amp;Ccedil;°0x20&amp;cedil;&amp;ouml;×&amp;Ouml;&amp;frac12;&amp;Uacute;
pos = n+m_xor;
pos %= 256;
if( pos<0x20 ) pos+=0x20;
tmpSnd[n+1] = *(pBuffer+n) ^ (tg_mima[pos]&amp;0x1F);
}
// ×&amp;icirc;&amp;ordm;ó&amp;Ograve;&amp;raquo;&amp;cedil;&amp;ouml;×&amp;Ouml;&amp;frac12;&amp;Uacute;'/r'&amp;sup2;&amp;raquo;±&amp;auml;
tmpSnd[n+1] = *(pBuffer+n);
strcpy(pBuffer, tmpSnd);
}
void Decrypt(char* pBuffer, DWORD dwBufferLength)
{
int len, m, pos;
BYTE m_xor;
if(pBuffer[strlen(pBuffer)-1]=='/r')pBuffer[strlen(pBuffer)-1] = '/0';
len = (int)strlen(pBuffer);
m_xor = *pBuffer;
for( m=1;
m<len;
m++ )
{
pos = m-1+m_xor;
pos %= 256;
if( pos<0x20 ) pos+=0x20;
*(pBuffer+m) ^= (tg_mima[pos]&amp;0x1F);
}
strcpy(pBuffer, pBuffer+1);
strcat(pBuffer, "/r");
}
 
PROGRAM SAMPLE;

{void} Encrypt ({char} Byte *pBuffer ,DWORD dwBufferLength )
begin


{char} Byte tmpSnd[256] ;
BYTE m_xor := rand ()MOD 256;
DWORD pos ,n ;

memset (tmpSnd ,'/0',256);

if (m_xor <0x20)m_xor +:= 0x20;


tmpSnd[0] := m_xor ;


for (n := 0;n <dwBufferLength -1;n ++)
begin


pos := n +m_xor ;
pos MOD := 256;
if (pos <0x20)pos +:= 0x20;
tmpSnd[n +1]:= *(pBuffer +n )XOR (tg_mima[pos] AND 0x1F);
end;



tmpSnd[n +1]:= *(pBuffer +n );
COPY (pBuffer ,tmpSnd );
end;

{void} Decrypt ({char} Byte *pBuffer ,DWORD dwBufferLength )
begin

Integer len ,m ,pos ;
BYTE m_xor ;

if (pBuffer[strlen (pBuffer )-1] = := '/r')pBuffer[strlen (pBuffer )-1]:= '/0';
len := (Integer )Length (pBuffer );
m_xor := *pBuffer ;
for (m := 1;m <len ;m ++)
begin

pos := m -1+m_xor ;
pos MOD := 256;
if (pos <0x20)pos +:= 0x20;
*(pBuffer +m )XOR := (tg_mima[pos] AND 0x1F);
end;

COPY (pBuffer ,pBuffer +1);
CONCAT (pBuffer ,'/r');
end;

end.
 
procedure Encrypt(pBuffer:pchar;
dwBufferLength:DWORD);
var
tmpSnd:array[0..256] of char;
pos,n:integer;
m_xor:byte;
begin
m_xor:=byte(random(256));
for n:=0 to 255do
tmpSnd[n]:=char(0);
if(m_xor<$20) then
inc(m_xor,$20);
tmpSnd[0] := m_xor;
for n:=0 to dwBufferLength-1do

begin
pos := n+m_xor;
pos :=(pos mod 256);
if( pos<$20 ) then
inc(pos,$20);
tmpSnd[n+1] := pBuffer[n+(tg_mima[pos] and $1F)];
end;

tmpSnd[n+1] := pBuffer[n];
strcopy(pBuffer, tmpSnd);
end;
 
大哥,还有一段解密呢?完成立马给分.
 
这是我回答的第一个问题
const tg_mima: array[0..255] of byte=
(
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,
$be, $84, $e1, $6c, $d6, $ae, $52, $90, $49, $f1, $f1, $bb, $e9, $eb, $b3, $a6,
$db, $87, $0c, $99, $5e, $0d, $1c, $06, $b7, $47, $de, $b3, $12, $4d, $c8, $43,
$bb, $8b, $a6, $1f, $03, $7d, $09, $38, $25, $1f, $d4, $cb, $fc, $96, $f5, $3b,
$13, $0d, $89, $0a, $1c, $db, $ae, $32, $20, $9a, $ee, $78, $36, $fd, $12, $32,
$f6, $9e, $49, $dc, $ad, $4f, $14, $f2, $44, $40, $d0, $c4, $30, $b7, $32, $3b,
$a1, $22, $f6, $22, $91, $9d, $e1, $8b, $1f, $da, $b0, $ca, $99, $02, $b9, $9d,
$49, $2c, $7e, $c5, $d5, $e9, $b2, $ea, $c9, $cc, $53, $bf, $67, $d6, $bf, $14,
$d6, $7e, $2d, $dc, $66, $ef, $57, $49, $61, $ff, $69, $61, $cd, $d1, $1e, $16,
$72, $72, $e6, $1d, $f0, $84, $4f, $4a, $77, $02, $d7, $e8, $39, $2c, $53, $cb,
$c9, $12, $1e, $33, $74, $9e, $0c, $f4, $d5, $d4, $9f, $d4, $59, $7e, $35, $cf,
$32, $22, $f4, $90, $2d, $48, $8f, $75, $e6, $1d, $2a, $e5, $f7, $2b, $78, $81,
$87, $44, $0e, $5f, $50, $00, $61, $8d, $be, $7b, $05, $15, $07, $3b, $33, $82,
$1f, $18, $70, $92, $da, $64, $54, $ce, $b1, $85, $3e, $69, $15, $46, $6a, $04,
$96, $73, $0e, $d9, $16, $2f, $67, $68, $d4, $4a, $4a, $d0, $57, $68, $76, $16
);
procedure Decrypt(pBuffer: PChar;
dwBufferLength: DWORD);
var
len, m, pos: Integer;
m_xor: Byte;
begin
if pBuffer[strlen(pBuffer)-1]=#13 then
pBuffer[strlen(pBuffer)-1] := #0;
len := integer(strlen(pBuffer));
m_xor := Byte(pBuffer);
for m := 1 to lendo
begin
pos := m-1+m_xor;
pos := pos mod 256;
if pos < $20 then
pos := pos + $20;
PChar(Byte(pBuffer) + m)^ := Char(tg_mima[pos] and $1F);
// *(pBuffer+m) ^= (tg_mima[pos]&amp;$1F);
end;
strcopy(pBuffer, pBuffer+1);
strcat(pBuffer, #13);
end;

procedure Encrypt(pBuffer:pchar;
dwBufferLength:DWORD);
var
tmpSnd:array[0..255] of char;
pos,n:integer;
m_xor:byte;
begin
m_xor:=byte(random(256));
for n:=0 to 255do
tmpSnd[n]:=char(0);
if(m_xor<$20) then
inc(m_xor,$20);
tmpSnd[0] := Char(m_xor);
for n:=0 to dwBufferLength-1do

begin
pos := n+m_xor;
pos :=(pos mod 256);
if( pos<$20 ) then
inc(pos,$20);
tmpSnd[n+1] := pBuffer[n+(tg_mima[pos] and $1F)];
end;

tmpSnd[n+1] := pBuffer[n];
strcopy(pBuffer, tmpSnd);
end;

有什么不明白的可以问(再线)
 
to 老人家:
调用 Decrypt 在这句 PChar(Byte(pBuffer) + m)^ := Char(tg_mima[pos] and $1F);
出错啦.
请赐教!
 
(pBuffer + m)^ := Char(tg_mima[pos] and $1F);
 
To DZHZH2000
留下你的mial 和 qq 以后好联系
 
to 老人家:
这是个字符串加密解密过程.请你用这个串试试'3 13019100567 1 OK'.
加密再解密后有时会丢失前几个.
还请大侠再赐教!
 
俺的EMAIL:dzhzh2000@yahoo.com.cn
qq:150043380
 
多人接受答案了。
 
顶部