📄 dataencodedlg.cpp
字号:
// DataEncodeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DataEncode.h"
#include "DataEncodeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
int asc;
int CHARtoINT1(char c)
{
switch(c)
{
case 'A':return 1;
case 'B':return 2;
case 'C':return 3;
case 'D':return 4;
case 'E':return 5;
case 'F':return 6;
case 'G':return 7;
case 'H':return 8;
case 'I':return 9;
case 'J':return 10;
case 'K':return 11;
case 'L':return 12;
case 'M':return 13;
case 'N':return 14;
case 'O':return 15;
case 'P':return 16;
case 'Q':return 17;
case 'R':return 18;
case 'S':return 19;
case 'T':return 20;
case 'U':return 21;
case 'V':return 22;
case 'W':return 23;
case 'X':return 24;
case 'Y':return 25;
case 'Z':return 26;
}
}
int CHARtoINT2(char c)
{
switch(c)
{
case 'a':return 1;
case 'b':return 2;
case 'c':return 3;
case 'd':return 4;
case 'e':return 5;
case 'f':return 6;
case 'g':return 7;
case 'h':return 8;
case 'i':return 9;
case 'j':return 10;
case 'k':return 11;
case 'l':return 12;
case 'm':return 13;
case 'n':return 14;
case 'o':return 15;
case 'p':return 16;
case 'q':return 17;
case 'r':return 18;
case 's':return 19;
case 't':return 20;
case 'u':return 21;
case 'v':return 22;
case 'w':return 23;
case 'x':return 24;
case 'y':return 25;
case 'z':return 26;
}
} //判断大小写,将字母与数字一一对应
char INTtoCHAR(int I)
{
switch(I)
{
case 1:if((asc>=65)&&(asc<=90)) return 'A';else return 'a';
case 2:if((asc>=65)&&(asc<=90)) return 'B';else return 'b';
case 3:if((asc>=65)&&(asc<=90)) return 'C';else return 'c';
case 4:if((asc>=65)&&(asc<=90)) return 'D';else return 'd';
case 5:if((asc>=65)&&(asc<=90)) return 'E';else return 'e';
case 6:if((asc>=65)&&(asc<=90)) return 'F';else return 'f';
case 7:if((asc>=65)&&(asc<=90)) return 'G';else return 'g';
case 8:if((asc>=65)&&(asc<=90)) return 'H';else return 'h';
case 9:if((asc>=65)&&(asc<=90)) return 'I';else return 'i';
case 10:if((asc>=65)&&(asc<=90)) return 'J';else return 'j';
case 11:if((asc>=65)&&(asc<=90)) return 'K';else return 'k';
case 12:if((asc>=65)&&(asc<=90)) return 'L';else return 'l';
case 13:if((asc>=65)&&(asc<=90)) return 'M';else return 'm';
case 14:if((asc>=65)&&(asc<=90)) return 'N';else return 'n';
case 15:if((asc>=65)&&(asc<=90)) return 'O';else return 'o';
case 16:if((asc>=65)&&(asc<=90)) return 'P';else return 'p';
case 17:if((asc>=65)&&(asc<=90)) return 'Q';else return 'q';
case 18:if((asc>=65)&&(asc<=90)) return 'R';else return 'r';
case 19:if((asc>=65)&&(asc<=90)) return 'S';else return 's';
case 20:if((asc>=65)&&(asc<=90)) return 'T';else return 't';
case 21:if((asc>=65)&&(asc<=90)) return 'U';else return 'u';
case 22:if((asc>=65)&&(asc<=90)) return 'V';else return 'v';
case 23:if((asc>=65)&&(asc<=90)) return 'W';else return 'w';
case 24:if((asc>=65)&&(asc<=90)) return 'X';else return 'x';
case 25:if((asc>=65)&&(asc<=90)) return 'Y';else return 'y';
case 0 :if((asc>=65)&&(asc<=90)) return 'Z';else return 'z';
}
}
//判断输入字母的ASCII值,将数字与字母一一对应
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()
/////////////////////////////////////////////////////////////////////////////
// CDataEncodeDlg dialog
CDataEncodeDlg::CDataEncodeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDataEncodeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDataEncodeDlg)
m_mingwen = _T("");
m_miwen = _T("");
m_k = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDataEncodeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDataEncodeDlg)
DDX_Text(pDX, IDC_EDIT1, m_mingwen);
DDX_Text(pDX, IDC_EDIT2, m_miwen);
DDX_Text(pDX, IDC_EDIT3, m_k);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDataEncodeDlg, CDialog)
//{{AFX_MSG_MAP(CDataEncodeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDataEncodeDlg message handlers
BOOL CDataEncodeDlg::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 CDataEncodeDlg::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 CDataEncodeDlg::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 CDataEncodeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDataEncodeDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CDataEncodeDlg::OnOK()
{
// TODO: Add extra validation here
int Length,i,j,m;
long int k;
CString input;
UpdateData(TRUE);
m_miwen=_T("");
k=m_k;
if(k>=2147483628)
{
MessageBox("k值超出可计算范围 ","提示",MB_OK | MB_ICONINFORMATION);
MessageBox("k值可计算范围是0-2147483627 ","提示",MB_OK | MB_ICONINFORMATION);
}
input=m_mingwen;
if ( input.IsEmpty() ) MessageBox("请输入明文 ","提示",MB_OK | MB_ICONINFORMATION);
// 错误处理
else
{
Length = input.GetLength();
for ( m=0;m<Length;m++ )
{
asc=input[m];
if((asc>=65)&&(asc<=90))
{
i = CHARtoINT1(input[m]);
}
else if((asc>=97)&&(asc<=122))
{
i = CHARtoINT2(input[m]);
}
else
{
MessageBox("您输入的明文中有数字、标点符号或者其他字符,请输入英文字母。 ","提示",MB_OK | MB_ICONINFORMATION);
m_miwen="Please input English Characters!";
break;
}
j=(i+k)%26;
m_miwen+=_T(INTtoCHAR(j));
} //密文的输出
}
UpdateData(FALSE);
}
//CDialog::OnOK();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -