📄 maxsha1dlg.cpp
字号:
// MaxSHA1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "MaxSHA1.h"
#include "MaxSHA1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
#include "SHA1.H"
#include "SHA1.C"
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CMaxSHA1Dlg dialog
CMaxSHA1Dlg::CMaxSHA1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMaxSHA1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMaxSHA1Dlg)
m_vMessage = _T("4313 4937 3634 3159 0669 0036 2020 1500 0000 0000");
m_vPassword = _T("在此输入密码信号");
m_vDigest = _T("C2D4 8422 FACE 8451 E630 B5BA 2734 BDB1 8E11 A8F6 ");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMaxSHA1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMaxSHA1Dlg)
DDX_Control(pDX, IDC_CHK_PASSWORD, m_cChkPassword);
DDX_Control(pDX, IDC_CHK_MESSAGE, m_cChkMessage);
DDX_Control(pDX, IDC_DIGEST, m_cDigest);
DDX_Control(pDX, IDC_PASSWORD, m_cPassword);
DDX_Control(pDX, IDC_MESSAGE, m_cMessage);
DDX_Text(pDX, IDC_MESSAGE, m_vMessage);
DDX_Text(pDX, IDC_PASSWORD, m_vPassword);
DDX_Text(pDX, IDC_DIGEST, m_vDigest);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMaxSHA1Dlg, CDialog)
//{{AFX_MSG_MAP(CMaxSHA1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_CALCULATE, OnBtnCalculate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMaxSHA1Dlg message handlers
BOOL CMaxSHA1Dlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CMaxSHA1Dlg::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 CMaxSHA1Dlg::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 CMaxSHA1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//功能: 将字符串转换成为十六进制数,
//输入: str: 输入字符串,其数据有效为'0'~'9','a'~'f','A'~'F',间隔符可有可无,有时须是数据之外的
// hex: 输出数据指针
// len: 输出数据缓冲最大长度,若字符串数据不够,返回实际个数,超出时返回len
//返回: 输出数据字节数
u16 StringToHex(char *str,u8 *hex,u16 len)
{
u16 i,j;
u8 chnew,chold;
u8 begin,stop;
begin=0;stop=0;chold=0;
for(i=0,j=0;j/2<len;i++){
chnew=*(str+i);
if (chnew==0) break;
else if (chnew>='0'&&chnew<='9') {chnew=chnew-'0';}
else if (chnew>='a'&&chnew<='f') {chnew=chnew-'a'+10;}
else if (chnew>='A'&&chnew<='F') {chnew=chnew-'A'+10;}
else {chnew=16;}
if(chnew<16){
if(j%2==0) hex[j/2] =chnew*16;
else hex[j/2]+=chnew;
j++;
}else if(chold<16){
if(j%2==1) {
hex[(j-1)/2]/=16;
j++;
}
}
chold=chnew;
}
for(i=j/2;i<len;i++)hex[i]=0; //结束符后全清零
return j/2;
}
void GetLicence(u8 BoardSn[20], u8 Key[20])
{
}
void CMaxSHA1Dlg::OnBtnCalculate()
{
// TODO: Add your control notification handler code here
u8 HexBuf[4096];
u16 m,n;
u8 Digest[20];
SHA1_CONTEXT ctx;
m_cMessage.GetWindowText(m_vMessage);
m = m_vMessage.GetLength();
if(m_cChkMessage.GetCheck()){
memcpy(HexBuf,m_vMessage.GetBuffer(m),m);
}else{
m = StringToHex(m_vMessage.GetBuffer(m),HexBuf,4096);
}
m_cPassword.GetWindowText(m_vPassword);
n = m_vPassword.GetLength();
if(m_cChkPassword.GetCheck()){
memcpy(HexBuf+m,m_vPassword.GetBuffer(n),n);
}else{
n = StringToHex(m_vPassword.GetBuffer(n),HexBuf+m,4096-m);
}
SHA1_Init( &ctx );
SHA1_Update( &ctx, HexBuf,m+n);
SHA1_Finish( &ctx, Digest );
CString tmpstr;
m_vDigest="";
for(int i=0;i<20;i++){
tmpstr.Format("%02X ",Digest[i]);
m_vDigest+=tmpstr;
}
m_cDigest.SetWindowText(m_vDigest);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -