风一样的男孩 发表于 2012-9-20 15:08:38

读取GHO文件密码算法

算法来源于GhoHash,由shuax写成了C语言的,方便集成到自己的程序中,收藏备用.
#include <stdio.h>   
#include <stdlib.h>   
#include <string.h>   
   
unsigned short table;   
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<len;i++)   
    {   
      unsigned short temp = table ^ (key>>8) ] ^ (key<<8);   
      buf = buf ^ 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 = FillTable(i, 4129, 1954);   
      }   
         
      //   
      FILE * fp = fopen(argv,"rb");   
      if(fp)   
      {   
            fseek(fp, 11, SEEK_SET);   
            char flag = fgetc(fp);   
            if(flag)   
            {   
                unsigned char encrypted1;   
                unsigned char encrypted2;   
                fread(encrypted1,1,15,fp);   
                fread(encrypted2,1,10,fp);   
                  
                //   
                int key = 0;   
                while(1)   
                {   
                  unsigned char temp;   
                  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;   
}
页: [1]
查看完整版本: 读取GHO文件密码算法