语言差异太大了,
int UnGateCode( char * in, char * out )
{
if( in == NULL )
return 0;
int lcnt = strlen( in ) >> 1;
if( lcnt == 0 )
return 0;
if( in[0] == (char)0)//'\0' )
return 0;
int i = 0;
int icode = 0;
int _edi = 0xf667; for( i = 0;i < lcnt;i ++ )
{
out[i] = ((hex2int( ucase( in[i * 2])) & 0xf )<<4);
out[i] += hex2int( ucase( in[i * 2 + 1])) & 0xf;
icode = ((int)out[i]) & 0xff;
out[i] ^= ((_edi & 0xffff)>>8);
_edi = (((_edi + icode ) * 0xce6d ) & 0xffff ) + 0x58bf; } out[lcnt] = (char)0;//'\0'; return 1;
}
int UnGateCode( char * in, char * out )
{
if( in == NULL )
return 0;
int lcnt = strlen( in ) >> 1;
if( lcnt == 0 )
return 0;
if( in[0] == (char)0)//'\0' )
return 0;
int i = 0;
int icode = 0;
int _edi = 0xf667; for( i = 0;i < lcnt;i ++ )
{
out[i] = ((hex2int( ucase( in[i * 2])) & 0xf )<<4);
out[i] += hex2int( ucase( in[i * 2 + 1])) & 0xf;
icode = ((int)out[i]) & 0xff;
out[i] ^= ((_edi & 0xffff)>>8);
_edi = (((_edi + icode ) * 0xce6d ) & 0xffff ) + 0x58bf; } out[lcnt] = (char)0;//'\0'; return 1;
}
解决方案 »
- datasource table adoquery让dbgrid显示出来数据,
- 关于版本号的问题。
- SQL里怎么实现使两个表相同的触发器?
- 请问:怎样得到一个字符串得宽度,不是长度????????????????????
- 各位高手! 怎么亲手做一个MPEG4的播放器? 难道真的要去找豪杰解霸作者??或者苦修VC??
- Object Pacscal基础问题
- 可以直接修改类名?
- 急急急呀!!各位高手请赶快相救呀,我怎么通过程序来控制midiaplay的播放呀,大家给我好的建议也好。
- 再次请教有关Delphi的3个比较有挑战性的问题,高手请进!
- 如何卸载ADO?比如2.1,2.5以及2.6的?
- 大家帮帮忙
- 这里有很多书!大家看一下噢up有分!
var
i,icode,edi,lcnt:integer;
begin
if in=null then
Result:=0;
lcnt:=lenght(in);
if lcnt=0 then
Result:=0;
if in[0]='\0' then
Result:=0;
i:=0;edi = 0xf667
iCode:=0; for i:=0 to lcnt-1 do
begin
out[i]:=((hex2int( ucase( in[i * 2])) & 0xf )<<4);
out[i] =out[i]+ hex2int( ucase( in[i * 2 + 1])) & 0xf;
icode = ((int)out[i]) & 0xff;
........................ end;
end;
var
lcnt,i,icode,_edi:integer;
begin
if in = NULL then
begin
result:=0;
exit;
end;
lcnt = length( in ) shr 1;
if lcnt = 0 then
begin
result:=0;
exit;
end;
if in[0] = ord(0) then
begin
result:=0;
exit;
end;
i := 0;
icode := 0;
_edi := $f667; for i := 0 to lcnt do
begin
out[i] := ((hex2int( ucase( in[i * 2])) and $f ) shl 4);
out[i] :=inc(out[i],hex2int( ucase( in[i * 2 + 1])) and $f);
icode := ((intger)out[i]) and $ff;
out[i]^:= ((_edi and $ffff) shr 8);
_edi := (((_edi + icode ) * $ce6d ) and $ffff ) + $58bf; end; out[lcnt] = ord(0); result:=1;
end;
var
lcnt,i,icode,_edi: integer;
p: pointer;
begin
if Tin = nil then
begin
result := 0;
exit;
end;
lcnt := Length(Tin) shr 1;
if Tin[0] = Char(0) then
begin
result := 0;
exit;
end;
i := 0;
icode := 0;
_edi := $f667;
p := Pointer((_edi and $ffff) shr 8);
for i:=0 to lcnt do
begin
Tout[i] := Char((integer(UpCase( Tin[i * 2])) and $f ) shl 4);
Tout[i] := Char(integer(Tout[i]) + integer( UpCase( Tin[i * 2 + 1])) and $f);
icode := integer(Tout[i]) and $ff;
Tout[i] := Char(P^); //out[i] ^= ((_edi & 0xffff)>>8);不知道是什么意思,瞎转换的!
_edi := (((_edi + icode ) * $ce6d ) and $ffff ) + $58bf;
end;
Tout[lcnt] := char(0);
result := 1;
end;
将函数作成dll或者ocx然后调用就非常简单了。
呵呵out[i] ^= ((_edi & 0xffff)>>8);
==>
out[i] = (out[i]) xor ((_edi & 0xffff)>>8); // Xor 指位异或, pascal没有对应的函数
1,上面的int2hex是个自定义函数相当于strtoint('$'+hexstr)
ucase是把小写字母转成大写!!
现在我不能理解的是:
1,out既然是pchar,out[i]又怎么会等于int类型?最不明白的!!!!!
2,out是字符串的话怎么会有out[0],字符串不是从1开始吗?所以原c程序中在
循环完了后又加了个char(0)。我个人觉得循环应该从1开始
c中字符串结束是‘\0’,delphi中是什么?
在C中,数组缺省的下标是从0开始,Delphi字符串中的字符下标从1开始,如果是短字符串,则读[0]为长度。
'\0'为Chr(0),或者#0
字符转成整数为Ord(AChar);
按你的说法那楼上的循环从0开始是错的。
在c中可以把一个integer赋值给char* out吗?(见循环中的前两行)
for (i = 0 ; str[i]; i++) {
....
...
}
这样的循环语句, 总之,在C里bool, char, int 都是"整型"可以混用.--2,out是字符串的话怎么会有out[0],字符串不是从1开始吗?所以原c程序中在
循环完了后又加了个char(0)。我个人觉得循环应该从1开始
c中字符串结束是‘\0’,delphi中是什么?
在C中字符串是以0开始的, 是值0结束的也就是 '\0'了,或者干脆0就行了,反正都一样.