📄 codedlg.cpp
字号:
// codeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "code.h"
#include "codeDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
unsigned long int pb=0xffffffff;
unsigned int jy_count;
unsigned int legth;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCodeDlg dialog
CCodeDlg::CCodeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCodeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCodeDlg)
m_l = _T("");
m_source = _T("");
m_fw = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCodeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCodeDlg)
DDX_Control(pDX, IDC_COMBO_FANWEI, m_fwc);
DDX_Control(pDX, IDC_BUTTON_JY, m_jy);
DDX_Text(pDX, IDC_EDIT_L, m_l);
DDX_Text(pDX, IDC_EDIT_SOURCE, m_source);
DDV_MaxChars(pDX, m_source, 12);
DDX_CBString(pDX, IDC_COMBO_FANWEI, m_fw);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCodeDlg, CDialog)
//{{AFX_MSG_MAP(CCodeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_CHANGE, OnButtonChange)
ON_BN_CLICKED(IDC_BUTTON_JY, OnButtonJy)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCodeDlg message handlers
BOOL CCodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_fwc.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCodeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCodeDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCodeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCodeDlg::Init_set()
{////////////////////?????????????????????********************
double ttt;
double kkk;
// unsigned long int mm[4];
//用户密钥
A=0x01234567;//最好每个版本修改。注意要与处理器的完全相同
B=0x89abcedf;//最好每个版本修改。注意要与处理器的完全相同
C=0xfedcba98;//最好每个版本修改。注意要与处理器的完全相同
D=0x76543210;//最好每个版本修改。注意要与处理器的完全相同
//中间处理密钥生成---一般不用修改。注意要与处理器的完全相同
for(int k=1;k<65;k++)
{
kkk=sin(k);
if(kkk<0)
kkk=kkk*(-1);
ttt=4294967296*kkk;
key_16[k-1]=ttt;
}
}
void CCodeDlg::OnButtonChange()
{
// TODO: Add your control notification handler code here
Init_set();
UpdateData(TRUE);
if (m_fw=="1")
{
pb=0xffffffff;
jy_count=1;
legth=48;
}
if (m_fw=="16")
{
pb=0xfffffff0;
jy_count=16;
legth=44;
}
if (m_fw=="256")
{
pb=0xffffff00;
jy_count=256;
legth=40;
}
if (m_fw=="1024")
{
pb=0xfffffc00;
jy_count=1024;
legth=38;
}
if (m_fw=="2048")
{
pb=0xfffff800;
jy_count=2048;
legth=37;
}
if (m_fw=="4096")
{
pb=0xfffff000;
jy_count=4096;
legth=36;
}
if (m_fw=="8192")
{
pb=0xffffe000;
jy_count=8192;
legth=35;
}
//Get source address 6Byte
source=m_source;
stringToHex();
Fill_ind();
Clycle_1();
}
void CCodeDlg::Clycle_1()
{
unsigned long int ooo;
Muc_program();
aa=A+aa;
bb=B+bb;
cc=C+cc;
dd=D+dd;
CString cs="";
CString cs1="";
CString cs2;
char ii;
for(int j=0;j<8;j++)
{
ii=(aa>>28);
cs1=cs1+Dec_hex_sim(ii);
aa=(aa<<4);
}
cs=cs+cs1;
cs1="";
for(j=0;j<8;j++)
{
ii=(bb>>28);
cs1=cs1+Dec_hex_sim(ii);
bb=(bb<<4);
}
cs=cs+cs1;
cs1="";
for(j=0;j<8;j++)
{
ii=(cc>>28);
cs1=cs1+Dec_hex_sim(ii);
cc=(cc<<4);
}
cs=cs+cs1;
cs1="";
for(j=0;j<8;j++)
{
ii=(dd>>28);
cs1=cs1+Dec_hex_sim(ii);
dd=(dd<<4);
}
cs=cs+cs1;
m_l=cs;
UpdateData(FALSE);
}
void CCodeDlg::Fill_ind()
{
ind[0]=(ind[14]<<16);
ind[0]=ind[0]+(ind[15]>>16);
ind[1]=ind[15]<<16;
ind[1]=ind[1]|(0x00008000*jy_count);
//Add length
ind[14]=0;
ind[15]=legth;
}
void CCodeDlg::stringToHex()
{
for(int i=0;i<16;i++)
ind[i]=0;
for(i=0;i<12;i++)
{
if(i<4)
{
ind[14]=ind[14]*16;
ind[14]=ind[14]+Change(source.GetAt(i));
}
else
{
ind[15]=ind[15]*16;
ind[15]=ind[15]+Change(source.GetAt(i));
}
}
ind[15]=ind[15]&pb;
}
CString CCodeDlg::Dec_hex_sim(unsigned char in2)
{
switch (in2){
case 0:
return "0";
case 1:
return "1";
case 2:
return "2";
case 3:
return "3";
case 4:
return "4";
case 5:
return "5";
case 6:
return "6";
case 7:
return "7";
case 8:
return "8";
case 9:
return "9";
case 10:
return "A";
case 11:
return "B";
case 12:
return "C";
case 13:
return "D";
case 14:
return "E";
case 15:
return "F";
default :
return "0";
}
}
unsigned char CCodeDlg::Change(char ch)
{
switch (ch){
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'A':
return 10;
case 'B':
return 11;
case 'C':
return 12;
case 'D':
return 13;
case 'E':
return 14;
case 'F':
return 15;
default :
return 0;
}
}
void CCodeDlg::OnButtonJy()
{
// TODO: Add your control notification handler code here
CString gg;
unsigned long int ind15,ind14;
UpdateData(TRUE);
if (m_fw=="1")
{
pb=0xffffffff;
jy_count=1;
legth=48;
}
if (m_fw=="16")
{
pb=0xfffffff0;
jy_count=16;
legth=44;
}
if (m_fw=="256")
{
pb=0xffffff00;
jy_count=256;
legth=40;
}
if (m_fw=="1024")
{
pb=0xfffffc00;
jy_count=1024;
legth=38;
}
if (m_fw=="2048")
{
pb=0xfffff800;
jy_count=2048;
legth=37;
}
if (m_fw=="4096")
{
pb=0xfffff000;
jy_count=4096;
legth=36;
}
if (m_fw=="8192")
{
pb=0xffffe000;
jy_count=8192;
legth=35;
}
source=m_source;
Init_set();
end_cou=0;
//Get source address 6Byte
stringToHex();
ind15=ind[15];
ind14=ind[14];
for(int add_num=0;add_num<address_number;add_num++)
{
unsigned long ing;
ing=ind15;
if(add_num!=0)
ind15=ind15+jy_count;
if(ind15<ing)
ind14++;
ind[15]=ind15;
ind[14]=ind14;
Fill_ind();
Clycle_2();
for(int i=0;i<16;i++)
ind[i]=0;
}
///////////////////////////////////////
BOOL b_c=0;
for(int i=0;i<address_number*4;i+=4)
{
unsigned long int e0;
unsigned long int e1;
unsigned long int e2;
unsigned long int e3;
e0=end[i];
e1=end[i+1];
e2=end[i+2];
e3=end[i+3];
for(int j=i+4;j<address_number*4;j+=4)
{
if((e0==end[j])&&(e1==end[j+1])&&(e2=end[j+2])&&(end[j+3]))
{
CString ce,ce1;
ce.Format("%d",i/4);
ce1.Format("%d",j/4);
ce=ce+"位置=";
ce1=ce1+"位置";
ce=ce+ce1;
MessageBox(ce);
b_c=1;
}
}
}
if(!b_c)
MessageBox("安全代码不重复!");
}
unsigned long int ooo;
void CCodeDlg::Clycle_2()
{
m_l="";
Muc_program();
end[end_cou]=aa;
end[end_cou+1]=bb;
end[end_cou+2]=cc;
end[end_cou+3]=dd;
end_cou=end_cou+4;
}
void CCodeDlg::Muc_program()//加到对方处理器中的算法处理程序
{
aa=A;
bb=B;
cc=C;
dd=D;
count=0;
//NO.1-1
f=((bb&cc)|((~bb)&dd));
ooo=aa+f+ind[0]+key_16[count];
for(int y=0;y<7;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
aa=bb+ooo;
count++;
f=((aa&bb)|((~aa)&cc));
ooo=dd+f+ind[1]+key_16[count];
for(y=0;y<12;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
dd=aa+ooo;
count++;
f=((dd&aa)|((~dd)&bb));
ooo=cc+f+ind[2]+key_16[count];
for(y=0;y<17;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
cc=dd+ooo;
count++;
f=((cc&dd)|((~cc)&aa));
ooo=bb+f+ind[3]+key_16[count];
for(y=0;y<22;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
bb=cc+ooo;
count++;
//NO.1-2
f=((bb&cc)|((~bb)&dd));
ooo=aa+f+ind[4]+key_16[count];
for(y=0;y<7;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
aa=bb+ooo;
count++;
f=((aa&bb)|((~aa)&cc));
ooo=dd+f+ind[5]+key_16[count];
for(y=0;y<12;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
dd=aa+ooo;
count++;
f=((dd&aa)|((~dd)&bb));
ooo=cc+f+ind[6]+key_16[count];
for(y=0;y<17;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
cc=dd+ooo;
count++;
f=((cc&dd)|((~cc)&aa));
ooo=bb+f+ind[7]+key_16[count];
for(y=0;y<22;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
bb=cc+ooo;
count++;
//NO.1-3
f=((bb&cc)|((~bb)&dd));
ooo=aa+f+ind[8]+key_16[count];
for(y=0;y<7;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
aa=bb+ooo;
count++;
f=((aa&bb)|((~aa)&cc));
ooo=dd+f+ind[9]+key_16[count];
for(y=0;y<12;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
dd=aa+ooo;
count++;
f=((dd&aa)|((~dd)&bb));
ooo=cc+f+ind[10]+key_16[count];
for(y=0;y<17;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
cc=dd+ooo;
count++;
f=((cc&dd)|((~cc)&aa));
ooo=bb+f+ind[11]+key_16[count];
for(y=0;y<22;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
bb=cc+ooo;
count++;
//NO.1-4
f=((bb&cc)|((~bb)&dd));
ooo=aa+f+ind[12]+key_16[count];
for(y=0;y<7;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
}
aa=bb+ooo;
count++;
f=((aa&bb)|((~aa)&cc));
ooo=dd+f+ind[13]+key_16[count];
for(y=0;y<12;y++)
{
if((ooo&0x80000000)==0x80000000)
{
ooo=ooo<<1;
ooo++;
}
else
ooo=ooo<<1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -