1、加解密处理系统题 目: 加解密处理系统 成员分工组长( )基于MFC文件加解密系统基于MFC运用ASCII码加解密字符串系统组员( )控制台中运用ASCII码加解密字符串系统基于MFC运用ASCII码加解密字符串系统组员( )控制台中运用ASCII码加解密字符串系统控制台中运用ASCII码文件加解密系统评分细则评分项优秀良好中等差遵守机房规章制度上机时的表现学习态度程序准备情况程序设计能力团队合作精神课题功能实现情况算法设计合理性用户界面设计报告书写认真程度内容详实程度文字表达熟练程度回答问题准确度简短评语 教师签名: 年 月 日评分等级 备注评分等级共五种:优秀、良好、中等、及格、不及格一、
2、课题内容和要求 加解密系统是实现对选定的文件或字符串(由数字或字母组成)进行加密解密的程序。可以将所需要的内容(整个文件或者输入的一行字符)加密,也可以将存储的加密文件翻译回来。基本要求:(1)从键盘输入要进行加密的一行字符串或者需要加密的文件名。(2)显示菜单:设置加密方法加密解密显示原始文件和解密文件(3)选择菜单,进行相应的操作。加密方法是设置一加密字符串以及对文件的哪些部分进行加密;加密是将原始文件加密并保存到文件中;解密是将加了密的文件还原并保存到文件中,同时应比较与原始文件的一致性;显示是将文件在屏幕上显示出来,供人工校对。选作要求:(1)设计美观实用的图形菜单界面(2)自行增加一
3、些新功能模块其他要求(1)在上述功能要求的基础上,为了提高成绩,可以添加一些额外的功能。(2)变量、函数命名符合规范。(3)注释详细:每个变量都要求有注释说明用途;函数有注释说明功能,对参数、返回值也要以注释的形式说明用途;关键的语句段要求有注释解释。(4)程序的层次清晰,可读性强二、需求分析 小组采用基于MFC的加解密系统,完成了对文件和字符串的加密,其中为了完成对汉字的加解密,小组稍微改动了一下提示的算法,以增强程序的能力。程序能将结果保存便于人工校验。 基于MFC的加解密系统功能框架图如图1所示。 图1 功能框架图(1)打开:通过打开按钮读入准备加密的文件。(2)另存为:将加密文件的密文
4、保存在文件中。(3)加密:对打开的文件加密。(4)解密:对保存在文件中的密文进行解密,得到原文件。(5)输入:由键盘键入将被加密的字符串。(6)加密:通过密钥对明文加密生成密文。(7)解密:对密文解密还原成明文。(8)输出:显示解密的结果。概要设计 (1)主要函数体:CString strEncrypTable = &)#?*/,_!; /设置可加密汉字、字符串的密钥CString EnCryptString(CString s) /加密函数CString UnEncryptString(CString s) /解密函数(1) 图2 加密流程图(2) 图3 解密流程图四、源程序代码 (1)按钮
5、事件函数 #include stdafx.h#include EnCry.h#include EnCryDlg.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CEnCryAppBEGIN_MESSAGE_MAP(CEnCryApp, CWinApp) /AFX_MSG_MAP(CEnCryApp) / NOTE - the ClassWizard will add and remove mapping macros here. / DO NOT EDIT wha
6、t you see in these blocks of generated code! /AFX_MSG ON_COMMAND(ID_HELP, CWinApp:OnHelp)END_MESSAGE_MAP()/ CEnCryApp constructionCEnCryApp:CEnCryApp() / TODO: add construction code here, / Place all significant initialization in InitInstance/ The one and only CEnCryApp objectCEnCryApp theApp;/ CEnC
7、ryApp initializationBOOL CEnCryApp:InitInstance() AfxEnableControlContainer(); / Standard initialization / If you are not using these features and wish to reduce the size / of your final executable, you should remove from the following / the specific initialization routines you do not need.#ifdef _A
8、FXDLL Enable3dControls(); / Call this when using MFC in a shared DLL#else Enable3dControlsStatic(); / Call this when linking to MFC statically#endif CEnCryDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse = IDOK) / TODO: Place code here to handle when the dialog is / dismissed
9、 with OK else if (nResponse = IDCANCEL) / TODO: Place code here to handle when the dialog is / dismissed with Cancel / Since the dialog has been closed, return FALSE so that we exit the / application, rather than start the applications message pump. return FALSE;/(2) 加解密函数(头文件)#include stdafx.h#incl
10、ude using namespace std;CString strEncrypTable = &)#?*/,_!;CString EnCryptString(CString s) /加密函数 CString DestStr = int iLength = s.GetLength(); string strtemp = s.GetBuffer(iLength); s.ReleaseBuffer(); unsigned char stemp1024; memset(stemp, 0, 1024); memcpy(stemp, strtemp.c_str(), iLength); CString
11、 h; for (int i=0; iiLength; i+) stempi = stempistempi+10xB8; h.Format(%d,stempi); if (h.GetLength() = 1) h = 00 + h; if (h.GetLength() = 2) h = 0 + h; for (int j=0; j3; j+) TCHAR tc = h.GetAt(j); int itemp = atoi(&tc); DestStr += strEncrypTable.GetAt(itemp); return DestStr;CString UnEncryptString(CS
12、tring s) int i,j; CString Deststr = ; CString sTemp = ; char ss1000; memset(ss,0,1000); for (i=0; is.GetLength(); i+) j = strEncrypTable.Find(s.GetAt(i); CString cstrtemp1; cstrtemp1.Format(%d,j); sTemp += cstrtemp1; j=0; for (i=0; i0; i-) ssi-1 = ssissi-10xB8; Deststr = ss; return Deststr;/((3)将加解密
13、函数传值到文本框中#include stdafx.h#include EnCry.h#include fstream#include EnCryDlg.h#include EnCryandUnEncry.h#include string#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifusing namespace std;/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic
14、: 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/ Implementationprotected: /AFX_MSG(CAboutDlg) vir
15、tual void OnOK(); /AFX_MSG DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD) /AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog) /AFX_MSG_
16、MAP(CAboutDlg) /AFX_MSG_MAPEND_MESSAGE_MAP()/ CEnCryDlg dialogCEnCryDlg:CEnCryDlg(CWnd* pParent /*=NULL*/) : CDialog(CEnCryDlg:IDD, pParent) /AFX_DATA_INIT(CEnCryDlg) m_strEdit = _T(); /AFX_DATA_INIT / Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()-LoadIc
17、on(IDR_MAINFRAME);void CEnCryDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CEnCryDlg) DDX_Text(pDX, IDC_EDIT1, m_strEdit); /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CEnCryDlg, CDialog) /AFX_MSG_MAP(CEnCryDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICK
18、ED(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()/ CEnCryDlg message handlersBOOL
19、 CEnCryDlg:OnInitDialog() m_strEdit=您好! 请在这里输入明文。; 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 AppendMenu(MF_SEPARATOR); pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTB
20、OX, strAboutMenu); / Set the icon for this dialog. The framework does this automatically / when the applications 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 se
21、t the focus to a controlvoid CEnCryDlg: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 applic
22、ations using the document/view model,/ this is automatically done for you by the framework.void CEnCryDlg:OnPaint() if (IsIconic() CPaintDC dc(this); / device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); / Center icon in client rectangle int cxIcon = GetSystemMet
23、rics(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 CEnCryDlg:OnQueryDragIcon() return (HCURSOR) m_hIcon;void CEnCryDlg:OnButtonEncry() /加密按钮事件 CString str; GetDlgItemText(IDC_EDIT1,str); CString cstr = str; CString cstrEnCry = EnCryptString(cstr); /明文窗体输入值传给加密 SetDlgItemText(IDC_ED
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1