📄 stringdlg.cpp
字号:
// StringDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DES.h"
#include "String.h"
#include "StringDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CStringDlg dialog
CStringDlg::CStringDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStringDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStringDlg)
m_length = 0;
m_key = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStringDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStringDlg)
DDX_Control(pDX, IDC_EDIT_CODE, m_editCode);
DDX_Control(pDX, IDC_EDIT_ORIGIN, m_editOrigin);
DDX_Text(pDX, IDC_EDIT3, m_length);
DDX_Text(pDX, IDC_EDIT_KEY, m_key);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStringDlg, CDialog)
//{{AFX_MSG_MAP(CStringDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_DES, OnBtnDes)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStringDlg message handlers
BOOL CStringDlg::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
SetDlgItemText(IDC_EDIT_KEY, "");
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CStringDlg::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 CStringDlg::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 CStringDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStringDlg::OnBtnDes()
{
// TODO: Add your control notification handler code here
char szOrigin[1024];
memset(szOrigin, 0, 1024);
GetDlgItemText(IDC_EDIT_ORIGIN, m_strOrigin);
m_length = m_strOrigin.GetLength();
SetDlgItemInt(IDC_EDIT3, m_length, FALSE);
memcpy(szOrigin, (LPSTR)(LPCTSTR)m_strOrigin, m_length);
// sprintf(szOrigin, "%s", m_strOrigin);
//去空格用的临时字符
char key[25];
key[24] = '\0';
memset(key, '0', 24);
GetDlgItemText(IDC_EDIT_KEY, m_key);
memcpy(key, (LPSTR)(LPCTSTR)m_key, m_key.GetLength());
// m_strCode += "\0";
// m_lengthCode = m_strCode.GetLength();
// LPTSTR strcode, padstr, endstr; //作为加密时的参数,因为RunDes和
// strcode = m_strCode.GetBuffer(0); //RunPad函数接受的字符串都是char*型
// padstr = m_strPad.GetBuffer(0); //所以我们将CString类的字符串的首地址
// endstr = m_strCodeEnd.GetBuffer(0); //赋给这些临时变量,当作参数传递
char szFilled[1024];
memset(szFilled, 0, 1024);
char szResult[1024];
memset(szResult, 0, 1024);
m_des.RunPad(m_des.PAD_PKCS_7, szOrigin, m_length, szFilled, m_padLen);
if (m_des.RunDes(m_des.ENCRYPT, m_des.ECB, szFilled, szResult, m_padLen, key, 24))
{
memset(szResult + m_padLen, 0, 1);
memcpy((LPSTR)(LPCTSTR)m_strCode, szResult, m_padLen + 1);
AfxMessageBox(m_strCode);
ASC_HEX(m_strCode, m_strCodeEnd);
}
m_strCodeEnd +="\0";
m_strCodeEnd.MakeUpper();
m_lastLength = strlen((LPSTR)(LPCTSTR)m_strCode);//m_strCode.GetLength();
SetDlgItemInt(IDC_EDIT1, m_padLen, FALSE);
SetDlgItemInt(IDC_EDIT2, m_lastLength, FALSE);
SetDlgItemText(IDC_EDIT_CODE, m_strCodeEnd);
}
void CStringDlg::ASC_HEX(CString strAsc, CString& strHex)
{
unsigned char szHex[4096];
memset(szHex, 0, 4096);
unsigned char szAsc[4096];
memset(szAsc, 0, 4096);
int nIndex = 0;
unsigned char szHexTemp[3];
memset(szHexTemp, 0, sizeof(szHexTemp));
//UpdateData(TRUE);
int length = strAsc.GetLength();
memcpy(szAsc, (LPSTR)(LPCSTR)strAsc, length);
while (nIndex < length)
{
memset(szHexTemp, 0, sizeof(szHexTemp));
unsigned int nTemp = (int)szAsc[nIndex];
//sprintf((char*)szHexTemp, "%02x", nTemp);
itoa(nTemp, (char*)szHexTemp, 16);
if(strlen((char*)szHexTemp) < 2)
{
szHexTemp[1] = szHexTemp[0];
szHexTemp[0] = '0';
szHexTemp[2] = '\0';
}
strcat((char*)szHex, (char*)szHexTemp);
nIndex++;
}
strcpy((LPSTR)(LPCSTR)strHex, (char*)szHex);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -