算法来源于GhoHash,我只是照着写成了C语言的,方便集成到自己的程序中。
#include#include #include unsigned short table[256]; int FillTable(int a, short b, int c) { int d = a << 8; for ( int i = 8; i > 0 ; --i) { if ( (c ^ d) & 0x8000) { c = b ^ (2 * c); } else { c *= 2; } d *= 2; } return c; } void decrypt(unsigned char *buf, int len, int key) { for(int i=0;i >8) ] ^ (key<<8); buf[i] = buf[i] ^ key; key = temp; } } int main(int argc,char *argv[]) { if(argc<2) { printf("使用方法:GetGhoPwd.exe ghost.gho"); } else { // for (int i=0;i<256;i++) { table[i] = FillTable(i, 4129, 1954); } // FILE * fp = fopen(argv[1],"rb"); if(fp) { fseek(fp, 11, SEEK_SET); char flag = fgetc(fp); if(flag) { unsigned char encrypted1[15]; unsigned char encrypted2[10]; fread(encrypted1,1,15,fp); fread(encrypted2,1,10,fp); // int key = 0; while(1) { unsigned char temp[15]; memcpy(temp, encrypted1, 15); decrypt(temp, 15, key); if( memcmp(temp,"BinaryResearch",15) ==0 ) { break; } key++; } // decrypt(encrypted2, 10, key); printf("此文件的密码是:%s", encrypted2); } else { printf("此文件没有密码保护。"); } fclose(fp); } } getchar(); return 0; }