📄 strdlg.cpp
字号:
// StrDlg.cpp : implementation file
//
#include "stdafx.h"
#include "AES.h"
#include "StrDlg.h"
#include "AESDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStrDlg dialog
CStrDlg::CStrDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStrDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStrDlg)
m_cipher = _T("");
m_deplaint = _T("");
m_time = _T("");
m_strlen = _T("");
m_plaint = _T("");
m_isfinished = _T("");
//}}AFX_DATA_INIT
}
void CStrDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStrDlg)
DDX_Control(pDX, IDC_CIPHER, m_cip);
DDX_Text(pDX, IDC_CIPHER, m_cipher);
DDX_Text(pDX, IDC_DEPLAINT, m_deplaint);
DDX_Text(pDX, IDC_TIME, m_time);
DDX_Text(pDX, IDC_STRLEN, m_strlen);
DDX_Text(pDX, IDC_PLAINT, m_plaint);
DDX_Text(pDX, IDC_ISFINISH, m_isfinished);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStrDlg, CDialog)
//{{AFX_MSG_MAP(CStrDlg)
ON_BN_CLICKED(IDC_ENCRYP, OnEncryp)
ON_BN_CLICKED(IDC_DECRYP, OnDecryp)
ON_EN_CHANGE(IDC_PLAINT, OnChangePlaint)
ON_BN_CLICKED(IDC_BUTCLC, OnButClc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStrDlg message handlers
BOOL CStrDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString str;
str.Format("%s","这是一个AES加密算法的演示程序! This is an example of AES!");
m_plaint=str;
m_strlen.Format("%ld",m_plaint.GetLength());
m_time.Format("0");
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStrDlg::OnEncryp()
{
// TODO: Add your control notification handler code here
UpdateData(true);
int Nk,Nr,sel;
long StarTime,EndTime;
CAESDlg *p_parent=(CAESDlg *)this->GetParentOwner();
if(p_parent->m_key.IsEmpty()||m_plaint.IsEmpty())
{
MessageBox("所提供的信息不全,无法执行此操作!","错误",MB_OK|MB_ICONWARNING);
return;
}
if(m_plaint.GetLength()<16)
{
MessageBox("所给定的明文字符串的长度必须大于等于16个字节!","错误",MB_OK|MB_ICONWARNING);
return;
}
StarTime=GetTickCount();//获取开始时间
sel=p_parent->m_lentype.GetCurSel();//取得密钥长度的类型
switch(sel)
{
case 0:Nk=4;Nr=10;break;
case 1:Nk=6;Nr=12;break;
case 2:Nk=8;Nr=14;break;
}
if(p_parent->m_key.GetLength()<Nk*4)
m_key=p_parent->m_keytemp;
else
m_key=p_parent->m_key;
if(aes.SetVariable(Nk,Nr,m_key)==false)
{
MessageBox(aes.ErrorMessage,"错误",MB_OK||MB_ICONWARNING);
return;
}
if(aes.SetString(m_plaint,m_cipher)==false)
{
MessageBox(aes.ErrorMessage,"错误",MB_OK||MB_ICONWARNING);
return;
}
m_time.Format("0");
m_isfinished.Format("正在加密字符串,这根据字符串的长度不同所需要的时间长度不一。请耐心等待!");
UpdateData(false);
aes.EncrypStr();
EndTime=GetTickCount();//获取完成时间
m_time.Format("%ld",EndTime-StarTime);
m_isfinished.Format("该字符串已经成功加密完成!");
int l=m_cipher.GetLength();
m_cip.SetWindowText(m_cipher);
UpdateData(false);
MessageBox("加密成功完成!","信息提示",MB_OK|MB_ICONINFORMATION);
}
void CStrDlg::OnDecryp()
{
// TODO: Add your control notification handler code here
UpdateData(true);
int Nk,Nr,sel;
long StarTime,EndTime;
CAESDlg *p_parent=(CAESDlg *)this->GetParentOwner();
if(p_parent->m_key.IsEmpty()||m_cipher.IsEmpty())
{
MessageBox("所提供的信息不全,无法执行此操作!","错误",MB_OK|MB_ICONWARNING);
return;
}
if(m_cipher.GetLength()<16)
{
MessageBox("所给定的密文字符串的长度必须大于等于16个字节!","错误",MB_OK|MB_ICONWARNING);
return;
}
StarTime=GetTickCount();//获取开始时间
sel=p_parent->m_lentype.GetCurSel();//取得密钥长度的类型
switch(sel)
{
case 0:Nk=4;Nr=10;break;
case 1:Nk=6;Nr=12;break;
case 2:Nk=8;Nr=14;break;
}
if(p_parent->m_key.GetLength()<Nk*4)
m_key=p_parent->m_keytemp;
else
m_key=p_parent->m_key;
if(aes.SetVariable(Nk,Nr,m_key)==false)
{
MessageBox(aes.ErrorMessage,"错误",MB_OK||MB_ICONWARNING);
return;
}
if(aes.SetString(m_cipher,m_deplaint)==false)
{
MessageBox(aes.ErrorMessage,"错误",MB_OK||MB_ICONWARNING);
return;
}
m_time.Format("0");
m_isfinished.Format("正在解密字符串,这根据字符串的长度不同所需要的时间长度不一。请耐心等待!");
UpdateData(false);
aes.DecrypStr();
EndTime=GetTickCount();//获取完成时间
m_time.Format("%ld",EndTime-StarTime);
m_isfinished.Format("该字符串已经成功解密完成!");
UpdateData(false);
MessageBox("解密成功完成!","信息提示",MB_OK|MB_ICONINFORMATION);
}
void CStrDlg::OnChangePlaint()
{
// 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.
UpdateData(true);
m_strlen.Format("%ld",m_plaint.GetLength());
UpdateData(false);
// TODO: Add your control notification handler code here
}
void CStrDlg::OnButClc()
{
// TODO: Add your control notification handler code here
CString str;
str.Format("%s","这是一个AES加密算法的演示程序! This is an example of AES!");
m_plaint=str;
m_strlen.Format("%ld",m_plaint.GetLength());
m_time.Format("0");
m_cipher=_T("");
m_deplaint=_T("");
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -