/*
*/
#include <windows.h>
#include <stdio.h>
????????????????????
????????????????????
#include <stdlib.h>
#include <time.h>
#include "avk326kg.h"
//-----------------------------------------------------------------------------
#define inline __inline
//-----------------------------------------------------------------------------
unsigned __int64 RND_SEED;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unsigned short SET_RND(unsigned long SEED, unsigned short DELTA)
{
?????????????????????????????????????????????????????????????;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unsigned long RND(unsigned long MODULUS)
{
??????????????????????????????????
return (RND_SEED>>32 & ?????????????) % MODULUS;
}
//-----------------------------------------------------------------------------
unsigned char REV_XLAT[256];
unsigned char XLAT[10];
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MAKE_XLAT()
{
int i, j; unsigned char ch;
memset(REV_XLAT, 10, sizeof(REV_XLAT)); for (i=0; i<10; i++)
{
again: switch (ch=RND(0xFF))
{
????????????????????????????????
????????????????????????????????
????????????????????????????????
case 0xDD: goto again;
default: if (ch < 0xC0 || ch > 0xDF) goto again;
}
for (j=0; j<i; j++) if (XLAT[j] == ch) goto again;
XLAT = ch; REV_XLAT[ch] = i;
}
for (i=0; i<10; i++) REV_XLAT[i+'0'] = i;
}
inline int C2I_XLAT (unsigned char idx) {return REV_XLAT[idx];}
inline char I2C_XLAT(int idx) {return XLAT[idx];}
//-----------------------------------------------------------------------------
unsigned long BSWAP(unsigned long dd)
{
????????????????????????????????????????
??????????????????????????????
??????????????????????????????
??????????????????????????????
??????????????????????????????
//-----------------------------------------------------------------------------
unsigned char HiNibble[16] =
{
0x00, 0x80, 0x40, 0xC0, ????, ????, ????, 0xE0,
0x10, ????, ????, ????, 0x30, 0xB0, 0x70, ????
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unsigned char LoNibble[16] =
{
????, 0x08, 0x04, 0x0C, ????, ????, ????, ????,
????, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unsigned long Scramble(unsigned long Num)
{
int i; unsigned char *N = (unsigned char*)&Num;
for(i=0; i<4; i++)
{
N = HiNibble[N & 0x0F] | LoNibble[N >> 4];
}
return BSWAP(Num);
}
//-----------------------------------------------------------------------------
signed char GMagic[3][16]={
{0x05, 0x04, 0x03, 0x02, 0x03, 0x11, 0x11, 0x05,
0x0B, 0x0C, 0x0D, 0x05, 0x02, 0x01, 0x03, 0x00},
{0x06, 0x03, 0x03, 0x02, 0x02, 0xA7, 0x11, 0x05,
0x0B, 0x0C, 0x0D, 0x05, 0x02, 0x01, 0x03, 0x00},
{0x07, 0x02, 0x02, 0x02, 0x01, 0x59, 0x11, 0x05,
0x0B, 0x0C, 0x0D, 0x05, 0x02, 0x01, 0x03, 0x00},
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
char* Garble(unsigned long Num[3], unsigned char X[19])
{
static char Buffer[100]; int i, j, B0, B1, B2;
unsigned long Res[3], Tmp;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
for (i=0; i<3; i++)
{
j = X[16+i]; // This info is coded somehow in X[0..15]
// but I decided to not to reverse corresponding X[...] datas
Res[j] = Num; // 256U*X[7]+X[8];
Res[j] = (Res[j]+BSWAP(Res[j])) >> X[5];
Res[j] = (Res[j] + (RND(27) << X[6])) >> 1;
Res[j] = RND(15) - Res[j];
Res[j] = Scramble(Res[j]);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
for (i=0; i<3; i++)
{
B1 = (Res & (1<<GMagic[ 6])) ? GMagic[11] : GMagic[12];
B2 = (Res & (1<<GMagic[ 7])) ? GMagic[13] : GMagic[14];
B0 = (Res & (1<<GMagic[ 8])) ? 1 :
(Res & (1<<GMagic[ 9])) ? 2 :
(Res & (1<<GMagic[10])) ? 3 : 0;
B0 = (Res & 1)+(Res & 0x100)/128;
Tmp = BSWAP(Res >> B1) >> 18; if (Tmp >= 9998) Tmp >>= B2;
Res += Tmp;
// 1..11 + 11..21 + 21..31 + bits(1..11)
Tmp = (Res & 0x7FF) + ((Res >> 11) & 0x3FF) + (Res >> 21);
Res &= 0x7FF; while (Res) {Tmp += Res&1; Res >>= 1;}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SET_RND(GMagic[5]*17, 1); MAKE_XLAT();
for (j=0; j<4; j++, Tmp /= 10)
{
Buffer[j+i*5] = j==B0 ? I2C_XLAT(Tmp % 10) : (Tmp % 10) + '0';
}
Buffer[4+i*5] = '.';
}
Buffer[i*5-1] = 0; return Buffer;
}
//-----------------------------------------------------------------------------
int UnGarble(char* Numb, unsigned long Num[3])
{
int i, j, n;
SET_RND(GMagic[0][5]*17, 1); MAKE_XLAT();
for (n=1, Num[j=0]=0, i=0; Numb; i++)
{
if (C2I_XLAT(Numb) < 10)
{
if (j > 2) return 0;
Num[j] += C2I_XLAT(Numb)*n; n*=10; if (n > 1000)
{
if (++j <= 2)
{
SET_RND(GMagic[j][5]*17, 1);
MAKE_XLAT(); Num[j] = 0;
}
n = 1;
}
} else if (Numb != '.' && Numb != ' ') return 0;
}
return j>2;
}
//-----------------------------------------------------------------------------
char* MakeRegNum()
{
static char Buffer[100]; unsigned long NUM;
NUM = rand() % 10000; NUM = NUM*10+7-(NUM % 7);
sprintf(Buffer, "%u", NUM); return Buffer;
}
//-----------------------------------------------------------------------------
unsigned char Magic_DC_PD1[19]={
0x05, 0x06, 0x07, 0x08, 0x01, 0x01, 0x04, 0x1B,
0x19, 0x77, 0xC7, 0x47, 0x7F, 0x7B, 0x14, 0x00,
0, 1, 2
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
char* MakePasswd_DC_PD1(char* CompCode)
{
unsigned long NUM[3];
if (!UnGarble(CompCode, NUM))
{
return "Invalid Code";
}
SET_RND(0x3B6BB9, 0x47);
return Garble(NUM, Magic_DC_PD1);
}
//-----------------------------------------------------------------------------
unsigned char Magic_DC[19]={
???????????????????????????????????????????????
???????????????????????????????
???????????????????????????????
???????????????????????????????
???????????????????????????????
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
char* MakePasswd_DC(char* CompCode)
{
unsigned long NUM[3], TMP;
if (!UnGarble(CompCode, NUM))
{
return "Invalid Code";
}
SET_RND(0xC6C33, 0x11);
return Garble(NUM, Magic_DC);
}
//-----------------------------------------------------------------------------
// D I A L O G F U N C T I O N
//-----------------------------------------------------------------------------
BOOL CALLBACK MainDialogProc
(
HWND hwnd, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static int FLASH=1; char BUF[0x100];
unsigned long NUM; int STATUS;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
switch (uMsg) { default: return FALSE;
case WM_CLOSE:
KillTimer(hwnd, 1); EndDialog(hwnd, 1); return TRUE;
case WM_INITDIALOG:
SetTimer(hwnd, 1, 200, NULL);
return TRUE;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case WM_TIMER: FLASH=!FLASH;
EnableWindow(GetDlgItem(hwnd, rFlash1), FLASH);
EnableWindow(GetDlgItem(hwnd, rFlash2), FLASH);
EnableWindow(GetDlgItem(hwnd, rFlash3), FLASH);
return TRUE;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case WM_COMMAND:
switch (LOWORD(wParam)) {
case rCompNum:
if (HIWORD(wParam)==EN_CHANGE)
{
GetDlgItemText(hwnd, rCompNum, BUF, sizeof(BUF)-1);
SetDlgItemText(hwnd, rRegNum, MakeRegNum());
SetDlgItemText(hwnd, rPassword_DC_PD1, MakePasswd_DC_PD1(BUF));
SetDlgItemText(hwnd, rPassword_DC, MakePasswd_DC(BUF));
}
break;
case rRegNumG:
SendDlgItemMessage(hwnd, rRegNum, EM_SETSEL, 0, -1);
SendDlgItemMessage(hwnd, rRegNum, WM_COPY, 0, 0);
break;
case rPasswordG_DC_PD1:
SendDlgItemMessage(hwnd, rPassword_DC_PD1, EM_SETSEL, 0, -1);
SendDlgItemMessage(hwnd, rPassword_DC_PD1, WM_COPY, 0, 0);
break;
case rPasswordG_DC:
SendDlgItemMessage(hwnd, rPassword_DC, EM_SETSEL, 0, -1);
SendDlgItemMessage(hwnd, rPassword_DC, WM_COPY, 0, 0);
break;
}
return TRUE;
} }
//-----------------------------------------------------------------------------
// E N T R Y P O I N T
//-----------------------------------------------------------------------------
int WINAPI WinMain
(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
srand(time(NULL));
LoadKeyboardLayout("00000419", KLF_ACTIVATE);
if (DialogBox(hInstance,MAKEINTRESOURCE(rMainDialog),
NULL,&MainDialogProc)==-1)
return MessageBox(NULL,"Unable to start main dialog",
"FATAL",MB_OK+MB_ICONERROR);
else return 0;
}