01.#include <stdio.h>
02.#include <stdlib.h>
03.#include <string.h>
04.
05.
06.unsigned short table[256];
07.int FillTable(int a, short b, int c)
08.{
09. int d = a << 8;
10. for ( int i = 8; i > 0 ; --i)
11. {
12. if ( (c ^ d) & 0x8000)
13. {
14. c = b ^ (2 * c);
15. }
16. else
17. {
18. c *= 2;
19. }
20. d *= 2;
21. }
22. return c;
23.}
24.
25.void decrypt(unsigned char *buf, int len, int key)
26.{
27. for(int i=0;i<len;i++)
28. {
29. unsigned short temp = table[buf[i] ^ (key>>8) ] ^ (key<<8);
30. buf[i] = buf[i] ^ key;
31. key = temp;
32. }
33.}
34.int main(int argc,char *argv[])
35.{
36. if(argc<2)
37. {
38. printf("使用方法:GetGhoPwd.exe ghost.gho");
39. }
40. else
41. {
42. //
43. for (int i=0;i<256;i++)
44. {
45. table[i] = FillTable(i, 4129, 1954);
46. }
47.
48. //
49. FILE * fp = fopen(argv[1],"rb");
50. if(fp)
51. {
52. fseek(fp, 11, SEEK_SET);
53. char flag = fgetc(fp);
54. if(flag)
55. {
56. unsigned char encrypted1[15];
57. unsigned char encrypted2[10];
58. fread(encrypted1,1,15,fp);
59. fread(encrypted2,1,10,fp);
60.
61. //
62. int key = 0;
63. while(1)
64. {
65. unsigned char temp[15];
66. memcpy(temp, encrypted1, 15);
67.
68. decrypt(temp, 15, key);
69.
70. if( memcmp(temp,"BinaryResearch",15) ==0 )
71. {
72. break;
73. }
74.
75. key++;
76. }
77.
78. //
79. decrypt(encrypted2, 10, key);
80. printf("此文件的密码是:%s", encrypted2);
81. }
82. else
83. {
84. printf("此文件没有密码保护。");
85. }
86. fclose(fp);
87. }
88. }
89. getchar();
90. return 0;
91.}C语言转Delphi
02.#include <stdlib.h>
03.#include <string.h>
04.
05.
06.unsigned short table[256];
07.int FillTable(int a, short b, int c)
08.{
09. int d = a << 8;
10. for ( int i = 8; i > 0 ; --i)
11. {
12. if ( (c ^ d) & 0x8000)
13. {
14. c = b ^ (2 * c);
15. }
16. else
17. {
18. c *= 2;
19. }
20. d *= 2;
21. }
22. return c;
23.}
24.
25.void decrypt(unsigned char *buf, int len, int key)
26.{
27. for(int i=0;i<len;i++)
28. {
29. unsigned short temp = table[buf[i] ^ (key>>8) ] ^ (key<<8);
30. buf[i] = buf[i] ^ key;
31. key = temp;
32. }
33.}
34.int main(int argc,char *argv[])
35.{
36. if(argc<2)
37. {
38. printf("使用方法:GetGhoPwd.exe ghost.gho");
39. }
40. else
41. {
42. //
43. for (int i=0;i<256;i++)
44. {
45. table[i] = FillTable(i, 4129, 1954);
46. }
47.
48. //
49. FILE * fp = fopen(argv[1],"rb");
50. if(fp)
51. {
52. fseek(fp, 11, SEEK_SET);
53. char flag = fgetc(fp);
54. if(flag)
55. {
56. unsigned char encrypted1[15];
57. unsigned char encrypted2[10];
58. fread(encrypted1,1,15,fp);
59. fread(encrypted2,1,10,fp);
60.
61. //
62. int key = 0;
63. while(1)
64. {
65. unsigned char temp[15];
66. memcpy(temp, encrypted1, 15);
67.
68. decrypt(temp, 15, key);
69.
70. if( memcmp(temp,"BinaryResearch",15) ==0 )
71. {
72. break;
73. }
74.
75. key++;
76. }
77.
78. //
79. decrypt(encrypted2, 10, key);
80. printf("此文件的密码是:%s", encrypted2);
81. }
82. else
83. {
84. printf("此文件没有密码保护。");
85. }
86. fclose(fp);
87. }
88. }
89. getchar();
90. return 0;
91.}C语言转Delphi
解决方案 »
- 我的程序调用一个CMD命令行程序,如何得到命令行程序的输出结果?
- FastReport关于分组打印的布局问题
- 动态数组怎么实现动态增加长度?
- 笔记本硬盘还是移动硬盘
- fastreport中demo中calendar的有关问题?
- 怎样将shape控件始终显示出来,也就是不被其他组件遮盖住??
- 请教:
- 关于Delphi+SQLserver安装程序的问题,高手指教
- 怪问题:我用dbase for window建一个.dbf的表,15个字段,在录入接近3万条记录时,我的表神秘地清空了,检查没有病毒,怀疑是不是超过了
- 如何判断一个程序已经在内存中?
- AdoQuery.delete 问题
- delphi用spcomm实现串口通信,数据能发送到串口调试工具,但是不能接受它们发过来的数据。
program Project1;{$APPTYPE CONSOLE}uses
Windows,
Classes,
SysUtils;var
table: array[0..255] of Byte;function FillTable(a: integer; b: SmallInt; c: integer): integer;
var
i, d: integer;
begin
d := a shl 8;
for i := 8 downto 1 do
begin
if (c xor d) and $8000 > 0 then
c := b xor (2* c)
else
c := c *2;
d := d *2;
end;
Result := c;
end;procedure decrypt(buf: array of Char; len, key: integer);
var
i: integer;
temp: Byte;
begin
for i := 0 to len - 1 do
begin
temp := table[Byte(buf[i]) xor (key shr 8)] xor (key shl 8);
buf[i] := Char(Byte(buf[i]) xor key);
key := temp;
end;
end;var
i: Byte;
Stream1: TMemoryStream;
flag: ShortInt;
encrypted1: array[0..14] of Char;
encrypted2: array[0..9] of Char;
key: integer;
temp: array[0..14] of Char;
begin
{ TODO -oUser -cConsole Main : Insert code here }
if (ParamCount < 2) then
Writeln('使用方法:GetGhoPwd.exe ghost.gho')
else
begin
for i := 0 to 255 do
table[i] := FillTable(i, 4129, 1954); Stream1 := TMemoryStream.Create;
try
Stream1.LoadFromFile(ParamStr(1));
Stream1.Seek(11, soFromBeginning);
Stream1.Read(flag, 1);
if Byte(flag) <> 0 then
begin
Stream1.Read(encrypted1[0], 15);
Stream1.Read(encrypted2[0], 10);
key := 0;
while True do
begin
CopyMemory(@temp[0], @encrypted1[0], 15);
decrypt(temp, 15, key);
//if CompareMem(@temp[0], PChar('BinaryResearch'), 15) then
if temp = 'BinaryResearch' then
Break; Inc(Key);
end;
//
decrypt(encrypted2, 10, key);
Writeln('此文件的密码是:' + encrypted2);
end
else
Writeln('此文件没有密码保护。');
finally
Stream1.Free;
end;
end;
ReadLn;
end.
C的还是D的代码运行出错??如果是D的,单步调试看下是哪句出的错,可能我翻译有点粗糙。
begin
CopyMemory(@temp[0], @encrypted1[0], 15);
decrypt(temp, 15, key);
//if CompareMem(@temp[0], PChar('BinaryResearch'), 15) then
if temp = 'BinaryResearch' then
Break; Inc(Key);
end;
var
handF : DWORD;
begin
....
handF := CreateFile(PChar('c:\ghost.gho'), GENERIC_READ, 0, nil,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); // 只读方式打开文件并返回文件句柄
FileSeek(handF , 11, 0); // 移动第11个字节到文件头部 ,0 头部 ,1 当前位置,2尾部
FileRead(handF , flag, 1); // 读第1个字节到 flag 里
....// 问题是 table[i] := FillTable(i, 4129, 1954); 如何解释 4129 和 1954
// 和 if( memcmp(temp,"BinaryResearch",15) ==0 ) 的 BinaryResearch 怎么来的