📄 cryptographydlg.cpp
字号:
// CryptographyDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Cryptography.h"
#include "CryptographyDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CCryptographyDlg dialog
CCryptographyDlg::CCryptographyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCryptographyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCryptographyDlg)
m_strInput = _T("");
m_strEncryptText = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCryptographyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCryptographyDlg)
DDX_Text(pDX, IDC_EDIT1, m_strInput);
DDX_Text(pDX, IDC_EDIT2, m_strEncryptText);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCryptographyDlg, CDialog)
//{{AFX_MSG_MAP(CCryptographyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CONFIRM_BUTTON, OnConfirmButton)
ON_BN_CLICKED(IDC_UNCODE_BUTTON, OnUncodeButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCryptographyDlg message handlers
BOOL CCryptographyDlg::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
int i=0,j=0;
for(j=0;j<8;j++)
{
EncryptIP[0][j]=j;
}
EncryptIP[1][0]=4;
EncryptIP[1][1]=5;
EncryptIP[1][2]=8;
EncryptIP[1][3]=1;
EncryptIP[1][4]=2;
EncryptIP[1][5]=7;
EncryptIP[1][6]=3;
EncryptIP[1][7]=6;
EncryptIP[2][0]=4;
EncryptIP[2][1]=5;
EncryptIP[2][2]=7;
EncryptIP[2][3]=1;
EncryptIP[2][4]=2;
EncryptIP[2][5]=8;
EncryptIP[2][6]=6;
EncryptIP[2][7]=3;
return TRUE; // return TRUE unless you set the focus to a control
}
void CCryptographyDlg::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 CCryptographyDlg::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 CCryptographyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCryptographyDlg::OnConfirmButton()
{
// TODO: Add your control notification handler code here
::SetWindowText(*GetDlgItem(IDC_EDIT2),"");
m_strEncryptText=""; //清空密文变量
UpdateData();
TCHAR *szOriginText=NULL; //存放明文字符串
TCHAR *szDestText=NULL; //存放密文
int iLength=m_strInput.GetLength()+1;
szOriginText=new TCHAR[iLength];
szDestText=new TCHAR[iLength];
//获取输入的明文
::GetWindowText(*GetDlgItem(IDC_EDIT1),szOriginText,iLength);
TCHAR szM[9]={"0"}; //存放待转换的8个明文
TCHAR szC[9]={"0"}; //存放加密过的8个明文
int i,j;
//开始加密
for(i=0;i<iLength;i+=8)
{
for(j=0;j<8;j++)
{
szDestText[i+j]=szOriginText[i+EncryptIP[1][j]-1];
}
}
::SetWindowText(*GetDlgItem(IDC_EDIT2),szDestText);
m_strEncryptText=szDestText;
m_strEncryptText.TrimRight();
UpdateData(FALSE);UpdateData();
}
void CCryptographyDlg::OnOK()
{
CDialog::OnOK();
}
void CCryptographyDlg::OnUncodeButton()
{
// TODO: Add your control notification handler code here
::SetWindowText(*GetDlgItem(IDC_EDIT1),"");
UpdateData();
TCHAR *szOriginText=NULL; //存放密文字符串
TCHAR *szDestText=NULL; //存放明文字符串
int iLength=m_strEncryptText.GetLength()+1;
szOriginText=new TCHAR[iLength];
szDestText=new TCHAR[iLength];
//获取输入的明文
//::GetWindowText(*GetDlgItem(IDC_EDIT1),szOriginText,iLength);
strcpy(szOriginText,m_strEncryptText);
int i,j;
//开始加密
char c;
for(i=0;i<iLength;i+=8)
{
for(j=0;j<8;j++)
{
c=szOriginText[i+EncryptIP[2][j]-1];
szDestText[i+j]=szOriginText[i+EncryptIP[2][j]-1];
//szDestText[i+EncryptIP[1][j]-1]=szOriginText[i+j];
}
}
m_strInput=szDestText;
m_strInput.TrimRight();
UpdateData(FALSE);
UpdateData();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -