哪位高手帮忙把C翻译成delphi,多谢static void encipher(unsigned int *const v, const unsigned int *const k, unsigned int *const w)
{
register unsigned int
y = ntohl(v[0]),
z = ntohl(v[1]),
a = ntohl(k[0]),
b = ntohl(k[1]),
c = ntohl(k[2]),
d = ntohl(k[3]),
n = 0x10, /* do encrypt 16 (0x10) times */
sum = 0,
delta = 0x9E3779B9; /* 0x9E3779B9 - 0x100000000 = -0x61C88647 */ while (n-- > 0) {
sum += delta;
y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
} w[0] = htonl(y); w[1] = htonl(z);
}static void decipher(unsigned int *const v, const unsigned int *const k, unsigned int *const w)
{
register unsigned int
y = ntohl(v[0]),
z = ntohl(v[1]),
a = ntohl(k[0]),
b = ntohl(k[1]),
c = ntohl(k[2]),
d = ntohl(k[3]),
n = 0x10,
sum = 0xE3779B90,
/* why this ? must be related with n value*/
delta = 0x9E3779B9; /* sum = delta<<5, in general sum = delta * n */
while (n-- > 0) {
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
sum -= delta;
} w[0] = htonl(y); w[1] = htonl(z);
}
{
register unsigned int
y = ntohl(v[0]),
z = ntohl(v[1]),
a = ntohl(k[0]),
b = ntohl(k[1]),
c = ntohl(k[2]),
d = ntohl(k[3]),
n = 0x10, /* do encrypt 16 (0x10) times */
sum = 0,
delta = 0x9E3779B9; /* 0x9E3779B9 - 0x100000000 = -0x61C88647 */ while (n-- > 0) {
sum += delta;
y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
} w[0] = htonl(y); w[1] = htonl(z);
}static void decipher(unsigned int *const v, const unsigned int *const k, unsigned int *const w)
{
register unsigned int
y = ntohl(v[0]),
z = ntohl(v[1]),
a = ntohl(k[0]),
b = ntohl(k[1]),
c = ntohl(k[2]),
d = ntohl(k[3]),
n = 0x10,
sum = 0xE3779B90,
/* why this ? must be related with n value*/
delta = 0x9E3779B9; /* sum = delta<<5, in general sum = delta * n */
while (n-- > 0) {
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
sum -= delta;
} w[0] = htonl(y); w[1] = htonl(z);
}
winsock2;procedure encipher(v: PUINT; const k: PUINT; w: PUINT);
var
y, Z, a, b, c,d, n, Sum, delta: UINT;
v1, k1: array of UINT;
begin
SetLength(v1, 2);
SetLength(k1, 4);
Move(v^, v1[0], SizeOf(UINT) * 2);
Move(k^, k1[0], SizeOf(UINT) * 4);
y := ntohl(v1[0]);
z := ntohl(v1[1]);
a := ntohl(k1[0]);
b := ntohl(k1[1]);
c := ntohl(k1[2]);
d := ntohl(k1[3]); n := $10; //* do encrypt 16 (0x10) times */
sum := 0;
delta := $9E3779B9; //* 0x9E3779B9 - 0x100000000 = -0x61C88647 */ while (n > 0) do
begin
Dec(n);
sum := sum + delta;
y := y + ((z shl 4) + a) xor (z + sum) xor ((z shr 5) + b);
z := z + ((y shl 4) + c) xor (y + sum) xor ((y shr 5) + d);
w^ := htonl(y);
inc(w);
w^ := htonl(z);
end;
end;
to sanguomi:帮忙把这个也看看吧,谢了,分数送上
var a, b, c, d, n, y, z, sum, delta: dword;
begin
y := ntohl(PLongWord(PChar(str) + 00)^);
z := ntohl(PLongWord(PChar(str) + 04)^);
a := ntohl(PLongWord(PChar(key) + 00)^);
b := ntohl(PLongWord(PChar(key) + 04)^);
c := ntohl(PLongWord(PChar(key) + 08)^);
d := ntohl(PLongWord(PChar(key) + 12)^);
n := $10; //* do encrypt 16 (0x10) times */
sum := $00;
delta := $9E3779B9; //* 0x9E3779B9 - 0x100000000 = -0x61C88647 */
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
while n > 0 do
begin
Dec(n);
sum := sum + delta;
y := y + ((z shl 4) + a) xor (z + sum) xor ((z shr 5) + b);
z := z + ((y shl 4) + c) xor (y + sum) xor ((y shr 5) + d);
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SetLength(result , 8);
PLongWord(PChar(result) + 00)^ := htonl(y);
PLongWord(PChar(result) + 04)^ := htonl(z);
end;
参考sanguomi,自己翻译了一个