// AES加密程序Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "AES加密程序.h"
#include "AES加密程序Dlg.h"
#include "AES.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()
/////////////////////////////////////////////////////////////////////////////
// CAESDlg dialog
CAESDlg::CAESDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAESDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAESDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAESDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAESDlg)
DDX_Control(pDX, IDC_RADIO1, m_keysize);
DDX_Control(pDX, IDC_RADIO5, m_mode);
DDX_Control(pDX, IDC_PROGRESS1, m_prog);
DDX_Control(pDX, IDC_STATIC3, m_OpenMWPath);
DDX_Control(pDX, IDC_STATIC2, m_SavePath);
DDX_Control(pDX, IDC_STATIC1, m_OpenPath);
DDX_Control(pDX, IDC_EDIT1, m_FileText);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAESDlg, CDialog)
//{{AFX_MSG_MAP(CAESDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnOpen)
ON_BN_CLICKED(IDC_BUTTON2, OnSavePath)
ON_BN_CLICKED(IDC_BUTTON7, OnOpenMWPath)
ON_BN_CLICKED(IDC_BUTTON3, OnBFileEn)
ON_BN_CLICKED(IDC_BUTTON4, OnBFileDe)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_RADIO1, Onkey128)
ON_BN_CLICKED(IDC_RADIO2, Onkey192)
ON_BN_CLICKED(IDC_RADIO3, Onkey256)
ON_BN_CLICKED(IDC_RADIO5, OnMode)
ON_BN_CLICKED(IDC_RADIO6, OnCBCmode)
ON_BN_CLICKED(IDC_RADIO7, OnOFBmode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAESDlg message handlers
BOOL CAESDlg::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 CAESDlg::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 CAESDlg::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 CAESDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAESDlg::OnOpen() //打开明文按钮
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE,"All File","*.*",OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,"All File(*.*)|*.*||");
if(dlg.DoModal()==IDOK)
{
strPathName=dlg.GetPathName();
CFile m_file(strPathName,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeRead|CFile::typeBinary);//二进制读,并新建文件(文件存在则不删除内容)
m_file.Read(strText.GetBuffer(m_file.GetLength()),m_file.GetLength());
strText.ReleaseBuffer();
filelen=m_file.GetLength();
m_file.Close();
m_FileText.SetWindowText(strText);
m_OpenPath.SetWindowText(strPathName);
}
Point=0;
Point1=0;
}
void CAESDlg::OnSavePath() //保存编辑框内容按钮
{
// TODO: Add your control notification handler code here
CFileDialog dlg(FALSE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"All Files(*.TXT)|*.TXT||",AfxGetMainWnd());
CString strPath,strText="";
char write[10000];
if(dlg.DoModal() == IDOK)
{
strPath = dlg.GetPathName();
if(strPath.Right(4) != ".TXT")
strPath += ".TXT";
m_SavePath.SetWindowText(strPath);
CFile file(_T(strPath),CFile::modeCreate|CFile::modeWrite);
m_FileText.GetWindowText(strText);
strcpy(write,strText);
file.Write(write,strText.GetLength());
file.Close();
}
}
void CAESDlg::OnOpenMWPath() //打开密文按钮
{
CFileDialog dlg(TRUE,"All File","*.*",OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,"All File(*.*)|*.*||");
if(dlg.DoModal()==IDOK)
{
strPathName=dlg.GetPathName();
CFile m_file(strPathName,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeRead|CFile::typeBinary);//二进制读,并新建文件(文件存在则不删除内容)
m_file.Read(strText.GetBuffer(m_file.GetLength()),m_file.GetLength());//m_file调用Read函数,GetBuffer制定缓冲区的大小,读取GetLength()的长度
strText.ReleaseBuffer();//释放缓冲区
filelen=m_file.GetLength();//长度赋予
m_file.Close();
m_OpenMWPath.SetWindowText(strPathName);
m_FileText.SetWindowText(strText);//编辑框输出内容
}
Point=0;
Point1=0;
}
void CAESDlg::OnChangeToNum()
{
}
void CAESDlg::OnKeySize() //选择密钥长度的函数
{
// TODO: Add your control notification handler code here
}
////////////////////////////////////////////////////////////////////////////////////////////////
//字符ASCII码值到字符字面值的转换 如 '0'转换成0, 'a'转换成10
int CAESDlg::char2num(char ch)
{
if(ch>='0'&&ch<='9')return ch-'0';
else if(ch>='a'&&ch<='f')return ch-'a'+10;
return -1;
}
////////////////////////////////////////////////////////////////////////////////////////////////
void CAESDlg::OnBFileEn() //文件加密函数
{
// TODO: Add your control notification handler code here
if(Point!=1||Point1!=1)
{
MessageBox("请先选择加密位数与加密模式");
return;
}
else if(strPathName=="")return;
FILE* finput;
FILE* foutput;
CString str1,str2,str3,str4;
finput=fopen((LPCTSTR)strPathName,"rb");//LPCTSTR = const TCHAR*
if(!finput)
{
MessageBox("文件打开错误","出错",MB_OK);
return;
}
fseek(finput,0,SEEK_END);
long lFileLen=ftell(finput); //ftell()函数返回文件位置指示符的当前值,即如果现在是在文件结尾,则这个值就是文件长度
fseek(finput,0,SEEK_SET);
long
MFC实现的AES加密程序
4星 · 超过85%的资源 需积分: 34 108 浏览量
2011-03-26
18:45:07
上传
评论
收藏 1.86MB RAR 举报
hukaijian
- 粉丝: 0
- 资源: 10
- 1
- 2
- 3
- 4
前往页