📄 descdlg.cpp
字号:
// descDlg.cpp : implementation file
//
#pragma comment(lib,"DES.lib");
#pragma comment(lib,"KEY.lib");
extern "C" _declspec(dllexport) void des_ky(void *kval, void *key);
extern "C" _declspec(dllexport) void des_ec(const void *i_blk, void *o_blk, void *key);
extern "C" _declspec(dllexport) void des_dc(const void *i_blk, void *o_blk, void *key);
extern "C" _declspec(dllexport) void des_ecX(const void *i_blk, void *o_blk, void *key, int index,unsigned long &ll0,unsigned long &ll1);
extern "C" _declspec(dllexport) void des_ecm(const void *i_blk, void *o_blk, void *key);
#include "stdafx.h"
#include "desc.h"
#include "descDlg.h"
#include "des.c"
#include "key.c"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
byte Mykey[1024];
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CDescDlg dialog
CDescDlg::CDescDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDescDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDescDlg)
m_csPlaintext = _T("");
m_csPassword = _T("");
m_csPaintextBin = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDescDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDescDlg)
DDX_Text(pDX, IDC_EDIT1, m_csPlaintext);
DDV_MaxChars(pDX, m_csPlaintext, 8);
DDX_Text(pDX, IDC_EDIT2, m_csPassword);
DDV_MaxChars(pDX, m_csPassword, 8);
DDX_Text(pDX, IDC_EDIT3, m_csPaintextBin);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDescDlg, CDialog)
//{{AFX_MSG_MAP(CDescDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDescDlg message handlers
BOOL CDescDlg::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 CDescDlg::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 CDescDlg::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 CDescDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDescDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CDescDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
//==》
void CDescDlg::OnButton4()
{
UpdateData();
char s[69]={0};
memcpy(s, m_csPlaintext, 8);
unsigned long l0, l1;
memcpy(&l0, s, 4);
memcpy(&l1, s + 4, 4);
sprintf(s, "%08X %08X", l0, l1);
SetDlgItemText(IDC_EDIT3, s);
}
//<<==
void CDescDlg::OnButton5()
{
unsigned long l0,l1;
char s[69]={0};
GetDlgItemText(IDC_EDIT6, s, 19);
sscanf(s, "%08X %08X", &l0, &l1);
memcpy(s,&l0, 4);
memcpy(s+4,&l1, 4);
s[8]=0;
SetDlgItemText(IDC_EDIT8, s);
}
//ip
void CDescDlg::OnButton1()
{
UpdateData();
char sOut[1024]={0};
unsigned long l0,l1;
des_ky(m_csPassword.GetBuffer(m_csPassword.GetLength()),Mykey);
des_ecX(m_csPlaintext.GetBuffer(8),
sOut, Mykey,
0,l0,l1);
char s[69]={0};
sprintf(s, "%08X %08X", l0, l1);
SetDlgItemText(IDC_EDIT4, s);
}
//16roand
void CDescDlg::OnButton2()
{
UpdateData();
char sOut[1024]={0};
unsigned long l0,l1;
des_ky(m_csPassword.GetBuffer(m_csPassword.GetLength()),Mykey);
des_ecX(m_csPlaintext.GetBuffer(8),
sOut, Mykey,
0,l0,l1);
char s[69]={0};
sprintf(s, "%08X %08X", l0, l1);
SetDlgItemText(IDC_EDIT4, s);
CString str="";
for(int i=1;i<=16;i++)
{
des_ecX(m_csPlaintext.GetBuffer(8),
sOut, Mykey,
i,l0,l1);
char s[69]={0};
sprintf(s, "%08X %08X\r\n", l0, l1);
str += s;
SetDlgItemText(IDC_EDIT5, str);
UpdateData(0);
MessageBox(s, "完成一轮计算",0);
}
}
//fp
void CDescDlg::OnButton3()
{
UpdateData();
char sOut[1024]={0};
unsigned long l0,l1;
des_ky(m_csPassword.GetBuffer(m_csPassword.GetLength()),Mykey);
des_ecX(m_csPlaintext.GetBuffer(8),
sOut, Mykey,
17,l0,l1);
char s[69]={0};
sprintf(s, "%08X %08X", l0, l1);
SetDlgItemText(IDC_EDIT6, s);
}
//jiemi
void CDescDlg::OnButton6()
{
UpdateData();
char sOut[1024]={0};
des_ky(m_csPassword.GetBuffer(m_csPassword.GetLength()),Mykey);
unsigned long l0,l1;
char s[69]={0};
GetDlgItemText(IDC_EDIT6, s, 19);
sscanf(s, "%08X %08X", &l0, &l1);
memcpy(s,&l0, 4);
memcpy(s+4,&l1, 4);
s[8]=0;
des_dc(s, sOut, Mykey);
sOut[8]=0;
SetDlgItemText(IDC_EDIT9, sOut);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -