寻C++、Delphi双修高手(10.01.14)

quark 2010-01-14 11:12:58
哪位高手帮忙把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);
}
...全文
126 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
quark 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sanguomi 的回复:]
翻译了一个,没测试
Delphi(Pascal) code
uses
winsock2;procedure encipher(v: PUINT;const k: PUINT; w: PUINT);var
y, Z, a, b, c,d, n, Sum, delta: UINT;
v1, k1:arrayof 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 encrypt16 (0x10) times*/
sum :=0;
delta := $9E3779B9;//* 0x9E3779B9- 0x100000000=-0x61C88647*/while (n>0)dobegin
Dec(n);
sum := sum+ delta;
y := y+ ((z shl4)+ a) xor (z+ sum) xor ((z shr5)+ b);
z := z+ ((y shl4)+ c) xor (y+ sum) xor ((y shr5)+ d);
w^ := htonl(y);
inc(w);
w^ := htonl(z);end;end;
[/Quote]

to sanguomi:

帮忙把这个也看看吧,谢了,分数送上
kfcoffe 2010-01-14
  • 打赏
  • 举报
回复
mark
sanguomi 2010-01-14
  • 打赏
  • 举报
回复
翻译了一个,没测试

uses
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;
wliaoc 2010-01-14
  • 打赏
  • 举报
回复
呵呵,本人不是
帮你顶一下
quark 2010-01-14
  • 打赏
  • 举报
回复
function QQEncipher(const str, key: string): string;
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,自己翻译了一个
内容概要:本文详细介绍了利用Simulink进行变压器开路试验的电路连接配置与仿真实现方法,重点在于通过仿真手段还原实际电力系统中变压器在空载条件下的电气特性,从而深入理解其工作原理与性能表现。文章作为电力系统仿真系列研究的一部分,系统阐述了从电路模型搭建、参数设定、仿真运行到结果分析的完整流程,突出展示了MATLAB/Simulink在电力设备建模与教学科研中的强大功能与应用价值。; 适合人群:具备电力系统基础知识,熟悉MATLAB/Simulink仿真环境,从事电气工程、自动化及相关领域的研发人员,以及高年级本科生和研究生。; 使用场景及目标:①掌握变压器开路试验的基本原理与Simulink仿真建模的具体步骤;②通过仿真实验深入理解空载电流、铁芯损耗及励磁特性等关键参数的物理意义;③为后续开展变压器短路试验、暂态过程分析以及其他电力设备的仿真研究奠定理论与实践基础。; 阅读建议:建议结合Simulink软件动手实践,逐步构建并调试电路模型,重点关注各元件参数的设置方法与测量模块的应用技巧,同时推荐参考文中提及的其他相关仿真案例进行拓展学习,以全面提升对电力系统仿真实践的整体认知与操作能力。

16,742

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧