⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 land.cpp

📁 这是一关于DES加密算法的C/C++实现范例
💻 CPP
字号:
// land.cpp : implementation file
//

#include "stdafx.h"
#include "实验一.h"
#include "land.h"
#include "DES.h"
#include "实验一Dlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#include "实验一.cpp"
/////////////////////////////////////////////////////////////////////////////
// Cland dialog


Cland::Cland(CWnd* pParent /*=NULL*/)
	: CDialog(Cland::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cland)
	m_username = _T("");
	m_password = _T("");
	//}}AFX_DATA_INIT
}


void Cland::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cland)
	DDX_Text(pDX, IDC_EDIT1, m_username);
	DDX_Text(pDX, IDC_EDIT2, m_password);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cland, CDialog)
	//{{AFX_MSG_MAP(Cland)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cland message handlers

void Cland::OnOK() 
{
	// TODO: Add extra validation here
	CString str,strname,strvalidation;
	UpdateData(TRUE);
	if(m_username=="") return;
	str="用户名与密码\\"+m_username+".use";
	CFile file;
	if(!file.Open(str,CFile::modeRead))
	{
		MessageBox("对不起,您输入的用户名不存在或密码错误。","提示:",MB_OK|MB_ICONQUESTION);
		m_username="";
		m_password="";
		UpdateData(false);

		return;
	}
	

	strname="用户名与密码\\被加密材料.doc";
	CFile ff(strname,CFile::modeRead);
	long lFileLen=ff.GetLength();
	long c=lFileLen/8;
	long d=lFileLen%8;
	strvalidation="用户名与密码\\确认材料.val";


	CFile fp(strvalidation,CFile::modeWrite);
	fp.SeekToBegin();
	ff.SeekToBegin();
	DES jm;

	char inbuff[8],oubuff[8],skey[8];
	memcpy(skey,(LPCTSTR)m_password,8);

	for(long i=0;i<c;i++)
	{
		ff.Read(inbuff,8);
		jm.Des_Go(oubuff, inbuff, sizeof(inbuff), skey,sizeof(skey), ENCRYPT);
		fp.Write(oubuff,8);
	}
	if(d>0)
	{
		ff.Read(inbuff,d);
		jm.Des_Go(oubuff, inbuff, sizeof(inbuff), skey,sizeof(skey), ENCRYPT);
		fp.Write(oubuff,8);
	}
	ff.Close();
	fp.Close();


	CFile fv(strvalidation,CFile::modeRead);
	long Len=file.GetLength();
	long Len1=fv.GetLength();
	if(Len!=Len1)
	{
		MessageBox("对不起,您输入的用户名不存在或密码错误。","提示:",MB_OK|MB_ICONQUESTION);
		m_username="";
		m_password="";
		UpdateData(false);
		return;
	}
	else
	{
		char m,n;
		char *buff1,*buff2;
//		c=Len/8;
//		d=Len%8;
		buff1=&m;
		buff2=&n;
		file.SeekToBegin();
		fv.SeekToBegin();
		for(i=0;i<Len;i++)
		{
			file.Read(buff1,1);
			fv.Read(buff2,1);
	//		buff1[7]='\0';
	//		buff2[7]='\0';
			if(m!=n)
			{
				MessageBox("对不起,您输入的用户名不存在或密码错误。","提示:",MB_OK|MB_ICONQUESTION);
				m_username="";
				m_password="";
				UpdateData(false);
				return;
			}
		}
/*		if(d>0)
		{
			file.Read(buff1,d);
			fv.Read(buff2,d);
			buff1[d+1]='\0';
			buff2[d+1]='\0';
			if(!strcmp(buff1,buff2))
			{
				MessageBox("对不起,您输入的用户名不存在或密码错误。","提示:",MB_OK|MB_ICONQUESTION);
				m_username="";
				m_password="";
				UpdateData(false);
				return;
			}
		}
		
*/  	MessageBox("登陆成功!","提示:",MB_OK|MB_ICONQUESTION);
		CWnd::ShowWindow(SW_HIDE);
		CMyDlg dlg1;
		dlg1.DoModal();
	}
    file.Close();
	fv.Close();
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -