加解密处理系统.docx
《加解密处理系统.docx》由会员分享,可在线阅读,更多相关《加解密处理系统.docx(30页珍藏版)》请在冰豆网上搜索。
加解密处理系统
题目:
成员分工
组长()
基于MFC文件加解密系统
基于MFC运用ASCII码加解密字符串系统
组员()
控制台中运用ASCII码加解密字符串系统
控制台中运用ASCII码文件加解密系统
评分细则
评分项
优秀
良好
中等
差
遵守机房规章制度
上机时的表现
学习态度
程序准备情况
程序设计能力
团队合作精神
课题功能实现情况
算法设计合理性
用户界面设计
报告书写认真程度
内容详实程度
文字表达熟练程度
回答问题准确度
简短评语
教师签名:
年月日
评分等级
备注
评分等级共五种:
优秀、良好、中等、及格、不及格
一、课题内容和要求
加解密系统是实现对选定的文件或字符串(由数字或字母组成)进行加密解密的程序。
可以将所需要的内容(整个文件或者输入的一行字符)加密,也可以将存储的加密文件翻译回来。
基本要求:
(1)从键盘输入要进行加密的一行字符串或者需要加密的文件名。
(2)显示菜单:
设置加密方法
加密
解密
显示原始文件和解密文件
(3)选择菜单,进行相应的操作。
加密方法是设置一加密字符串以及对文件的哪些部分进行加密;加密是将原始文件加密并保存到文件中;解密是将加了密的文件还原并保存到文件中,同时应比较与原始文件的一致性;显示是将文件在屏幕上显示出来,供人工校对。
选作要求:
(1)设计美观实用的图形菜单界面
(2)自行增加一些新功能模块
其他要求
(1)在上述功能要求的基础上,为了提高成绩,可以添加一些额外的功能。
(2)变量、函数命名符合规范。
(3)注释详细:
每个变量都要求有注释说明用途;函数有注释说明功能,对参数、返回值也要以注释的形式说明用途;关键的语句段要求有注释解释。
(4)程序的层次清晰,可读性强
二、需求分析
小组采用基于MFC的加解密系统,完成了对文件和字符串的加密,其中为了完成对汉字的加解密,小组稍微改动了一下提示的算法,以增强程序的能力。
程序能将结果保存便于人工校验。
基于MFC的加解密系统功能框架图如图1所示。
图1功能框架图
(1)打开:
通过打开按钮读入准备加密的文件。
(2)另存为:
将加密文件的密文保存在文件中。
(3)加密:
对打开的文件加密。
(4)解密:
对保存在文件中的密文进行解密,得到原文件。
(5)输入:
由键盘键入将被加密的字符串。
(6)加密:
通过密钥对明文加密生成密文。
(7)解密:
对密文解密还原成明文。
(8)输出:
显示解密的结果。
概要设计
(1)主要函数体:
CStringstrEncrypTable="@&)#?
*/,_!
";//设置可加密汉字、字符串的密钥
CStringEnCryptString(CStrings)//加密函数
CStringUnEncryptString(CStrings)//解密函数
(1)
图2加密流程图
(2)
图3解密流程图
四、源程序代码
(1)按钮事件函数
#include"stdafx.h"
#include"EnCry.h"
#include"EnCryDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CEnCryApp
BEGIN_MESSAGE_MAP(CEnCryApp,CWinApp)
//{{AFX_MSG_MAP(CEnCryApp)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG
ON_COMMAND(ID_HELP,CWinApp:
:
OnHelp)
END_MESSAGE_MAP()
//CEnCryAppconstruction
CEnCryApp:
CEnCryApp()
{
//TODO:
addconstructioncodehere,
//PlaceallsignificantinitializationinInitInstance
}
//TheoneandonlyCEnCryAppobject
CEnCryApptheApp;
//CEnCryAppinitialization
BOOLCEnCryApp:
InitInstance()
AfxEnableControlContainer();
//Standardinitialization
//Ifyouarenotusingthesefeaturesandwishtoreducethesize
//ofyourfinalexecutable,youshouldremovefromthefollowing
//thespecificinitializationroutinesyoudonotneed.
#ifdef_AFXDLL
Enable3dControls();//CallthiswhenusingMFCinasharedDLL
#else
Enable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically
CEnCryDlgdlg;
m_pMainWnd=&dlg;
intnResponse=dlg.DoModal();
if(nResponse==IDOK)
Placecodeheretohandlewhenthedialogis
//dismissedwithOK
elseif(nResponse==IDCANCEL)
//dismissedwithCancel
//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe
//application,ratherthanstarttheapplication'smessagepump.
returnFALSE;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
(2)加解密函数(头文件)
#include
usingnamespacestd;
";
CStringDestStr=""
intiLength=s.GetLength();
stringstrtemp=s.GetBuffer(iLength);
s.ReleaseBuffer();
unsignedcharstemp[1024];
memset(stemp,0,1024);
memcpy(stemp,strtemp.c_str(),iLength);
CStringh;
for(inti=0;i{stemp[i]=stemp[i]^stemp[i+1]^0xB8;h.Format("%d",stemp[i]);if(h.GetLength()==1){h="00"+h;}if(h.GetLength()==2){h="0"+h;}for(intj=0;j<3;j++){TCHARtc=h.GetAt(j);intitemp=atoi(&tc);DestStr+=strEncrypTable.GetAt(itemp);}}returnDestStr;} CStringUnEncryptString(CStrings){inti,j;CStringDeststr="";CStringsTemp="";charss[1000];memset(ss,0,1000);for(i=0;i{j=strEncrypTable.Find(s.GetAt(i));CStringcstrtemp1;cstrtemp1.Format("%d",j);sTemp+=cstrtemp1;}j=0;for(i=0;i{CStringcstrtemp=sTemp.Right(sTemp.GetLength()-i);cstrtemp=cstrtemp.Left(3);ss[j++]=(unsignedchar)(atoi(cstrtemp.GetBuffer(cstrtemp.GetLength())));cstrtemp.ReleaseBuffer();}for(i=j;i>0;i--){ss[i-1]=ss[i]^ss[i-1]^0xB8;}Deststr=ss;returnDeststr;}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////( (3)将加解密函数传值到文本框中#include"stdafx.h"#include"EnCry.h"#include"fstream"#include"EnCryDlg.h"#include"EnCryandUnEncry.h"#include"string"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endifusingnamespacestd;///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public:CAboutDlg();//DialogData//{{AFX_DATA(CAboutDlg)enum{IDD=IDD_ABOUTBOX};//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected://{{AFX_MSG(CAboutDlg)virtualvoidOnOK();//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CEnCryDlgdialogCEnCryDlg::CEnCryDlg(CWnd*pParent/*=NULL*/):CDialog(CEnCryDlg::IDD,pParent){//{{AFX_DATA_INIT(CEnCryDlg)m_strEdit=_T("");//}}AFX_DATA_INIT//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);}voidCEnCryDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CEnCryDlg)DDX_Text(pDX,IDC_EDIT1,m_strEdit);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CEnCryDlg,CDialog)//{{AFX_MSG_MAP(CEnCryDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON_ENCRY,OnButtonEncry)ON_EN_CHANGE(IDC_EDIT1,OnChangeEdit1)ON_BN_CLICKED(IDC_BUTTON_ENCRY2,OnButtonEncry2)ON_BN_CLICKED(IDC_BUTTON1,OnButton1)ON_EN_CHANGE(IDC_EDIT2,OnChangeEdit2)ON_BN_CLICKED(IDC_BUTTON2,OnButton2)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CEnCryDlgmessagehandlersBOOLCEnCryDlg::OnInitDialog(){m_strEdit="您好!请在这里输入明文。";CDialog::OnInitDialog();//Add"About..."menuitemtosystemmenu.//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX<0xF000);CMenu*pSysMenu=GetSystemMenu(FALSE);if(pSysMenu!=NULL){CStringstrAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if(!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);}}//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplication'smainwindowisnotadialogSetIcon(m_hIcon,TRUE);//SetbigiconSetIcon(m_hIcon,FALSE);//Setsmallicon//TODO:AddextrainitializationherereturnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCEnCryDlg::OnSysCommand(UINTnID,LPARAMlParam){if((nID&0xFFF0)==IDM_ABOUTBOX){CAboutDlgdlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID,lParam);}}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCEnCryDlg::OnPaint(){if(IsIconic()){CPaintDCdc(this);//devicecontextforpaintingSendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);//CentericoninclientrectangleintcxIcon=GetSystemMetrics(SM_CXICON);intcyIcon=GetSystemMetrics(SM_CYICON);CRectrect;GetClientRect(&rect);intx=(rect.Width()-cxIcon+1)/2;inty=(rect.Height()-cyIcon+1)/2;//Drawtheicondc.DrawIcon(x,y,m_hIcon);}else{CDialog::OnPaint();}}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCEnCryDlg::OnQueryDragIcon(){return(HCURSOR)m_hIcon;}voidCEnCryDlg::OnButtonEncry()//加密按钮事件{CStringstr;GetDlgItemText(IDC_EDIT1,str);CStringcstr=str;CStringcstrEnCry=EnCryptString(cstr);//明文窗体输入值传给加密SetDlgItemText(IDC_ED
stemp[i]=stemp[i]^stemp[i+1]^0xB8;
h.Format("%d",stemp[i]);
if(h.GetLength()==1)
h="00"+h;
if(h.GetLength()==2)
h="0"+h;
for(intj=0;j<3;j++)
TCHARtc=h.GetAt(j);
intitemp=atoi(&tc);
DestStr+=strEncrypTable.GetAt(itemp);
returnDestStr;
CStringUnEncryptString(CStrings)
inti,j;
CStringDeststr="";
CStringsTemp="";
charss[1000];
memset(ss,0,1000);
for(i=0;i{j=strEncrypTable.Find(s.GetAt(i));CStringcstrtemp1;cstrtemp1.Format("%d",j);sTemp+=cstrtemp1;}j=0;for(i=0;i{CStringcstrtemp=sTemp.Right(sTemp.GetLength()-i);cstrtemp=cstrtemp.Left(3);ss[j++]=(unsignedchar)(atoi(cstrtemp.GetBuffer(cstrtemp.GetLength())));cstrtemp.ReleaseBuffer();}for(i=j;i>0;i--){ss[i-1]=ss[i]^ss[i-1]^0xB8;}Deststr=ss;returnDeststr;}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////( (3)将加解密函数传值到文本框中#include"stdafx.h"#include"EnCry.h"#include"fstream"#include"EnCryDlg.h"#include"EnCryandUnEncry.h"#include"string"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endifusingnamespacestd;///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public:CAboutDlg();//DialogData//{{AFX_DATA(CAboutDlg)enum{IDD=IDD_ABOUTBOX};//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected://{{AFX_MSG(CAboutDlg)virtualvoidOnOK();//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CEnCryDlgdialogCEnCryDlg::CEnCryDlg(CWnd*pParent/*=NULL*/):CDialog(CEnCryDlg::IDD,pParent){//{{AFX_DATA_INIT(CEnCryDlg)m_strEdit=_T("");//}}AFX_DATA_INIT//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);}voidCEnCryDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CEnCryDlg)DDX_Text(pDX,IDC_EDIT1,m_strEdit);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CEnCryDlg,CDialog)//{{AFX_MSG_MAP(CEnCryDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON_ENCRY,OnButtonEncry)ON_EN_CHANGE(IDC_EDIT1,OnChangeEdit1)ON_BN_CLICKED(IDC_BUTTON_ENCRY2,OnButtonEncry2)ON_BN_CLICKED(IDC_BUTTON1,OnButton1)ON_EN_CHANGE(IDC_EDIT2,OnChangeEdit2)ON_BN_CLICKED(IDC_BUTTON2,OnButton2)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CEnCryDlgmessagehandlersBOOLCEnCryDlg::OnInitDialog(){m_strEdit="您好!请在这里输入明文。";CDialog::OnInitDialog();//Add"About..."menuitemtosystemmenu.//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX<0xF000);CMenu*pSysMenu=GetSystemMenu(FALSE);if(pSysMenu!=NULL){CStringstrAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if(!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);}}//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplication'smainwindowisnotadialogSetIcon(m_hIcon,TRUE);//SetbigiconSetIcon(m_hIcon,FALSE);//Setsmallicon//TODO:AddextrainitializationherereturnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCEnCryDlg::OnSysCommand(UINTnID,LPARAMlParam){if((nID&0xFFF0)==IDM_ABOUTBOX){CAboutDlgdlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID,lParam);}}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCEnCryDlg::OnPaint(){if(IsIconic()){CPaintDCdc(this);//devicecontextforpaintingSendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);//CentericoninclientrectangleintcxIcon=GetSystemMetrics(SM_CXICON);intcyIcon=GetSystemMetrics(SM_CYICON);CRectrect;GetClientRect(&rect);intx=(rect.Width()-cxIcon+1)/2;inty=(rect.Height()-cyIcon+1)/2;//Drawtheicondc.DrawIcon(x,y,m_hIcon);}else{CDialog::OnPaint();}}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCEnCryDlg::OnQueryDragIcon(){return(HCURSOR)m_hIcon;}voidCEnCryDlg::OnButtonEncry()//加密按钮事件{CStringstr;GetDlgItemText(IDC_EDIT1,str);CStringcstr=str;CStringcstrEnCry=EnCryptString(cstr);//明文窗体输入值传给加密SetDlgItemText(IDC_ED
j=strEncrypTable.Find(s.GetAt(i));
CStringcstrtemp1;
cstrtemp1.Format("%d",j);
sTemp+=cstrtemp1;
j=0;
for(i=0;i{CStringcstrtemp=sTemp.Right(sTemp.GetLength()-i);cstrtemp=cstrtemp.Left(3);ss[j++]=(unsignedchar)(atoi(cstrtemp.GetBuffer(cstrtemp.GetLength())));cstrtemp.ReleaseBuffer();}for(i=j;i>0;i--){ss[i-1]=ss[i]^ss[i-1]^0xB8;}Deststr=ss;returnDeststr;}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////( (3)将加解密函数传值到文本框中#include"stdafx.h"#include"EnCry.h"#include"fstream"#include"EnCryDlg.h"#include"EnCryandUnEncry.h"#include"string"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endifusingnamespacestd;///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public:CAboutDlg();//DialogData//{{AFX_DATA(CAboutDlg)enum{IDD=IDD_ABOUTBOX};//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected://{{AFX_MSG(CAboutDlg)virtualvoidOnOK();//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CEnCryDlgdialogCEnCryDlg::CEnCryDlg(CWnd*pParent/*=NULL*/):CDialog(CEnCryDlg::IDD,pParent){//{{AFX_DATA_INIT(CEnCryDlg)m_strEdit=_T("");//}}AFX_DATA_INIT//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);}voidCEnCryDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CEnCryDlg)DDX_Text(pDX,IDC_EDIT1,m_strEdit);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CEnCryDlg,CDialog)//{{AFX_MSG_MAP(CEnCryDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON_ENCRY,OnButtonEncry)ON_EN_CHANGE(IDC_EDIT1,OnChangeEdit1)ON_BN_CLICKED(IDC_BUTTON_ENCRY2,OnButtonEncry2)ON_BN_CLICKED(IDC_BUTTON1,OnButton1)ON_EN_CHANGE(IDC_EDIT2,OnChangeEdit2)ON_BN_CLICKED(IDC_BUTTON2,OnButton2)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CEnCryDlgmessagehandlersBOOLCEnCryDlg::OnInitDialog(){m_strEdit="您好!请在这里输入明文。";CDialog::OnInitDialog();//Add"About..."menuitemtosystemmenu.//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX<0xF000);CMenu*pSysMenu=GetSystemMenu(FALSE);if(pSysMenu!=NULL){CStringstrAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if(!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);}}//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplication'smainwindowisnotadialogSetIcon(m_hIcon,TRUE);//SetbigiconSetIcon(m_hIcon,FALSE);//Setsmallicon//TODO:AddextrainitializationherereturnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCEnCryDlg::OnSysCommand(UINTnID,LPARAMlParam){if((nID&0xFFF0)==IDM_ABOUTBOX){CAboutDlgdlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID,lParam);}}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCEnCryDlg::OnPaint(){if(IsIconic()){CPaintDCdc(this);//devicecontextforpaintingSendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);//CentericoninclientrectangleintcxIcon=GetSystemMetrics(SM_CXICON);intcyIcon=GetSystemMetrics(SM_CYICON);CRectrect;GetClientRect(&rect);intx=(rect.Width()-cxIcon+1)/2;inty=(rect.Height()-cyIcon+1)/2;//Drawtheicondc.DrawIcon(x,y,m_hIcon);}else{CDialog::OnPaint();}}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCEnCryDlg::OnQueryDragIcon(){return(HCURSOR)m_hIcon;}voidCEnCryDlg::OnButtonEncry()//加密按钮事件{CStringstr;GetDlgItemText(IDC_EDIT1,str);CStringcstr=str;CStringcstrEnCry=EnCryptString(cstr);//明文窗体输入值传给加密SetDlgItemText(IDC_ED
CStringcstrtemp=sTemp.Right(sTemp.GetLength()-i);
cstrtemp=cstrtemp.Left(3);
ss[j++]=(unsignedchar)(atoi(cstrtemp.GetBuffer(cstrtemp.GetLength())));
cstrtemp.ReleaseBuffer();
for(i=j;i>0;i--)
ss[i-1]=ss[i]^ss[i-1]^0xB8;
Deststr=ss;
returnDeststr;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////(
(3)将加解密函数传值到文本框中
#include"fstream"
#include"EnCryandUnEncry.h"
#include"string"
//CAboutDlgdialogusedforAppAbout
classCAboutDlg:
publicCDialog
public:
CAboutDlg();
//DialogData
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTBOX};
//}}AFX_DATA
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
//{{AFX_MSG(CAboutDlg)
virtualvoidOnOK();
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
CAboutDlg():
CDialog(CAboutDlg:
IDD)
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
voidCAboutDlg:
DoDataExchange(CDataExchange*pDX)
CDialog:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
//CEnCryDlgdialog
CEnCryDlg:
CEnCryDlg(CWnd*pParent/*=NULL*/)
CDialog(CEnCryDlg:
IDD,pParent)
//{{AFX_DATA_INIT(CEnCryDlg)
m_strEdit=_T("");
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
voidCEnCryDlg:
//{{AFX_DATA_MAP(CEnCryDlg)
DDX_Text(pDX,IDC_EDIT1,m_strEdit);
BEGIN_MESSAGE_MAP(CEnCryDlg,CDialog)
//{{AFX_MSG_MAP(CEnCryDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_ENCRY,OnButtonEncry)
ON_EN_CHANGE(IDC_EDIT1,OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON_ENCRY2,OnButtonEncry2)
ON_BN_CLICKED(IDC_BUTTON1,OnButton1)
ON_EN_CHANGE(IDC_EDIT2,OnChangeEdit2)
ON_BN_CLICKED(IDC_BUTTON2,OnButton2)
//CEnCryDlgmessagehandlers
BOOLCEnCryDlg:
OnInitDialog()
m_strEdit="您好!
请在这里输入明文。
OnInitDialog();
//Add"About..."menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX<0xF000);
CMenu*pSysMenu=GetSystemMenu(FALSE);
if(pSysMenu!
=NULL)
CStringstrAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!
strAboutMenu.IsEmpty())
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'smainwindowisnotadialog
SetIcon(m_hIcon,TRUE);//Setbigicon
SetIcon(m_hIcon,FALSE);//Setsmallicon
Addextrainitializationhere
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
OnSysCommand(UINTnID,LPARAMlParam)
if((nID&0xFFF0)==IDM_ABOUTBOX)
CAboutDlgdlgAbout;
dlgAbout.DoModal();
else
OnSysCommand(nID,lParam);
//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
//thisisautomaticallydoneforyoubytheframework.
OnPaint()
if(IsIconic())
CPaintDCdc(this);//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);
//Centericoninclientrectangle
intcxIcon=GetSystemMetrics(SM_CXICON);
intcyIcon=GetSystemMetrics(SM_CYICON);
CRectrect;
GetClientRect(&rect);
intx=(rect.Width()-cxIcon+1)/2;
inty=(rect.Height()-cyIcon+1)/2;
//Drawtheicon
dc.DrawIcon(x,y,m_hIcon);
OnPaint();
//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags
//theminimizedwindow.
HCURSORCEnCryDlg:
OnQueryDragIcon()
return(HCURSOR)m_hIcon;
OnButtonEncry()//加密按钮事件
CStringstr;
GetDlgItemText(IDC_EDIT1,str);
CStringcstr=str;
CStringcstrEnCry=EnCryptString(cstr);//明文窗体输入值传给加密
SetDlgItemText(IDC_ED
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1