⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.h

📁 通用注册机源程序
💻 H
字号:
//---------------------------------------------------------------------------
#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TEdit *Edit1;
        TEdit *Edit2;
        TMemo *Memo1;
        TButton *Button1;
        TButton *Button2;
        TButton *Button3;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall Button2Click(TObject *Sender);
        void __fastcall Button3Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#define f_rnd(i,a,b,c,d)                \
        u = _lrotl(d*(d+d+1), 5);       \
        t = _lrotl(b*(b+b+1), 5);       \
        a = _lrotl(a^t, u)+l_key[i];    \
        c = _lrotl(c^u, t)+l_key[i+1]

unsigned long l_key[44];
//////////设置注册序列
void set_key(const unsigned char *key)
{
 unsigned long i, j, k, a, b, l[8];

 unsigned long in_key[256];
 j = 0;
 k = 32;
 for(i=0; i<256; i++)
    in_key[i] = 0;
 for(i=strlen(key); i>0; i--) {
    if(k >= 32) {
       k = 0;
       in_key[j] = 0;
       j++;
       }
    in_key[j-1] |= (key[i-1]<<k);
    k += 8;
    }

 l_key[0] = 0xb7e15163;
 for(k=1; k<44; k++)
    l_key[k] = l_key[k-1]+0x9e3779b9;
 for(k=0; k<8; k++)
    l[k] = in_key[k];
 a = b = i = j = 0;
 for(k=0; k<132; k++) {
    a = _lrotl(l_key[i]+a+b, 3); b += a;
    b = _lrotl(l[j]+b, b);
    l_key[i] = a; l[j] = b;
    i = (i==43 ? 0 : i+1);
    j = (j==7 ? 0 : j+1);
    }
}
//////////转换成数字
char ConvertTable[]="0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+";
int GetIndex(char n)
{
 int i = -1;
 ConvertTable[64] = n;
 while(ConvertTable[++i]!=n);
 return i>63 ? 63 : i;
}
//////////加密,生成序列号
void encrypt(const unsigned char *tin, unsigned char *tout)
{
 unsigned long a, b, c, d, t, u;

 unsigned char _tin[16], _tout[16];
 unsigned long in_blk[4], out_blk[4];

 int i, k;
 i = k = 0;
 while(i<12) {
    _tin[i++] = GetIndex(tin[k])|GetIndex(tin[k+1])<<6;
    _tin[i++] = GetIndex(tin[k+1])>>2|GetIndex(tin[k+2])<<4;
    _tin[i++] = GetIndex(tin[k+2])>>4|GetIndex(tin[k+3])<<2;
    k += 4;
    }
 _tin[12] = _tin[13] = _tin[14] = _tin[15] = 0;

 in_blk[0] = _tin[0]|(_tin[1]<<8)|(_tin[2]<<16)|(_tin[3]<<24);
 in_blk[1] = _tin[4]|(_tin[5]<<8)|(_tin[6]<<16)|(_tin[7]<<24);
 in_blk[2] = _tin[8]|(_tin[9]<<8)|(_tin[10]<<16)|(_tin[11]<<24);
 in_blk[3] = _tin[12]|(_tin[13]<<8)|(_tin[14]<<16)|(_tin[15]<<24);

 a = in_blk[0]; b = in_blk[1]+l_key[0];
 c = in_blk[2]; d = in_blk[3]+l_key[1];

 f_rnd( 2,a,b,c,d); f_rnd( 4,b,c,d,a);
 f_rnd( 6,c,d,a,b); f_rnd( 8,d,a,b,c);
 f_rnd(10,a,b,c,d); f_rnd(12,b,c,d,a);
 f_rnd(14,c,d,a,b); f_rnd(16,d,a,b,c);
 f_rnd(18,a,b,c,d); f_rnd(20,b,c,d,a);
 f_rnd(22,c,d,a,b); f_rnd(24,d,a,b,c);
 f_rnd(26,a,b,c,d); f_rnd(28,b,c,d,a);
 f_rnd(30,c,d,a,b); f_rnd(32,d,a,b,c);
 f_rnd(34,a,b,c,d); f_rnd(36,b,c,d,a);
 f_rnd(38,c,d,a,b); f_rnd(40,d,a,b,c);

 out_blk[0] = a+l_key[42]; out_blk[1] = b;
 out_blk[2] = c+l_key[43]; out_blk[3] = d;

 _tout[0] = out_blk[0]&0x000000ff;  _tout[1] = (out_blk[0]>>8)&0x000000ff;  _tout[2] = (out_blk[0]>>16)&0x000000ff;  _tout[3] = (out_blk[0]>>24)&0x000000ff;
 _tout[4] = out_blk[1]&0x000000ff;  _tout[5] = (out_blk[1]>>8)&0x000000ff;  _tout[6] = (out_blk[1]>>16)&0x000000ff;  _tout[7] = (out_blk[1]>>24)&0x000000ff;
 _tout[8] = out_blk[2]&0x000000ff;  _tout[9] = (out_blk[2]>>8)&0x000000ff;  _tout[10] = (out_blk[2]>>16)&0x000000ff; _tout[11] = (out_blk[2]>>24)&0x000000ff;
 _tout[12] = out_blk[3]&0x000000ff; _tout[13] = (out_blk[3]>>8)&0x000000ff; _tout[14] = (out_blk[3]>>16)&0x000000ff; _tout[15] = (out_blk[3]>>24)&0x000000ff;

 for(i=0; i<16; i++)
    tout[i] = ConvertTable[_tout[i]&0x3f];
 tout[16] = 0;
}
//////////解密,还原成硬件代码
/*void decrypt(unsigned char *tin, unsigned char *tout)
{
 unsigned long a, b, c, d, t, u;

 unsigned char _tin[16], _tout[16];
 unsigned long in_blk[4], out_blk[4];
 for(int i=0; i<16; i++)
    _tin[i] = (GetNum(tin[i<<1])<<4)|GetNum(tin[(i<<1)+1]);
 in_blk[0] = _tin[0]|(_tin[1]<<8)|(_tin[2]<<16)|(_tin[3]<<24);
 in_blk[1] = _tin[4]|(_tin[5]<<8)|(_tin[6]<<16)|(_tin[7]<<24);
 in_blk[2] = _tin[8]|(_tin[9]<<8)|(_tin[10]<<16)|(_tin[11]<<24);
 in_blk[3] = _tin[12]|(_tin[13]<<8)|(_tin[14]<<16)|(_tin[15]<<24);

 d = in_blk[3]; c = in_blk[2] - l_key[43];
 b = in_blk[1]; a = in_blk[0] - l_key[42];

 i_rnd(40,d,a,b,c); i_rnd(38,c,d,a,b);
 i_rnd(36,b,c,d,a); i_rnd(34,a,b,c,d);
 i_rnd(32,d,a,b,c); i_rnd(30,c,d,a,b);
 i_rnd(28,b,c,d,a); i_rnd(26,a,b,c,d);
 i_rnd(24,d,a,b,c); i_rnd(22,c,d,a,b);
 i_rnd(20,b,c,d,a); i_rnd(18,a,b,c,d);
 i_rnd(16,d,a,b,c); i_rnd(14,c,d,a,b);
 i_rnd(12,b,c,d,a); i_rnd(10,a,b,c,d);
 i_rnd( 8,d,a,b,c); i_rnd( 6,c,d,a,b);
 i_rnd( 4,b,c,d,a); i_rnd( 2,a,b,c,d);

 out_blk[3] = d - l_key[1]; out_blk[2] = c;
 out_blk[1] = b - l_key[0]; out_blk[0] = a;

 _tout[0]=out_blk[0]&0x000000ff;  _tout[1]=(out_blk[0]>>8)&0x000000ff;  _tout[2]=(out_blk[0]>>16)&0x000000ff;  _tout[3]=(out_blk[0]>>24)&0x000000ff;
 _tout[4]=out_blk[1]&0x000000ff;  _tout[5]=(out_blk[1]>>8)&0x000000ff;  _tout[6]=(out_blk[1]>>16)&0x000000ff;  _tout[7]=(out_blk[1]>>24)&0x000000ff;
 _tout[8]=out_blk[2]&0x000000ff;  _tout[9]=(out_blk[2]>>8)&0x000000ff;  _tout[10]=(out_blk[2]>>16)&0x000000ff; _tout[11]=(out_blk[2]>>24)&0x000000ff;
 _tout[12]=out_blk[3]&0x000000ff; _tout[13]=(out_blk[3]>>8)&0x000000ff; _tout[14]=(out_blk[3]>>16)&0x000000ff; _tout[15]=(out_blk[3]>>24)&0x000000ff;

// char hex[]="0123456789ABCDEF";
// for (int i=0; i<32; i++) {
//   tout[i++] = hex[_tout[i>>1]/16];
//   tout[i] = hex[_tout[i>>1]%16];
//   }
// tout[32] = 0;

 int i, k;
 i = k = 0;
 while(i<16) {
    tout[i++] = ConvertTable[_tout[k]&0x3f];
    tout[i++] = ConvertTable[(_tout[k]>>6|_tout[k+1]<<2)&0x3f];
    tout[i++] = ConvertTable[(_tout[k+1]>>4|_tout[k+2]<<4)&0x3f];
    tout[i++] = ConvertTable[_tout[k+2]>>2];
    k += 3;
    }
 tout[16] = 0;
}*/
//---------------------------------------------------------------------------
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -