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

📄 testcrypt4dlg.cpp

📁 这是一个加解密程序
💻 CPP
字号:
// TestCrypt4Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "TestCrypt4.h"
#include "TestCrypt4Dlg.h"

#include "ZTeaCryptor.h"
#include "DemoData.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestCrypt4Dlg dialog

CTestCrypt4Dlg::CTestCrypt4Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestCrypt4Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestCrypt4Dlg)
	m_Password = _T("98765432109876543210");
	m_FileName = _T("A0.txt");
	m_Name1    = _T("李四");
	m_Name2    = _T("");
	m_Code1    = 123456789;
	m_Code2    = 0;
	m_ID1      = _T("abcdefghijklmn");
	m_ID2      = _T("");
	m_Addr1    = _T("Hello,this is a test.");
	m_Addr2    = _T("");
	
	
	
	
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestCrypt4Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestCrypt4Dlg)
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_Password);
	DDX_Text(pDX, IDC_EDIT_ADDR1, m_Addr1);
	DDX_Text(pDX, IDC_EDIT_ADDR2, m_Addr2);
	DDX_Text(pDX, IDC_EDIT_FILENAME, m_FileName);
	DDX_Text(pDX, IDC_EDIT_ID1, m_ID1);
	DDX_Text(pDX, IDC_EDIT_ID2, m_ID2);
	DDX_Text(pDX, IDC_EDIT_NAME1, m_Name1);
	DDX_Text(pDX, IDC_EDIT_NAME2, m_Name2);
	DDX_Text(pDX, IDC_EDIT_CODE1, m_Code1);
	DDX_Text(pDX, IDC_EDIT_CODE2, m_Code2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestCrypt4Dlg, CDialog)
	//{{AFX_MSG_MAP(CTestCrypt4Dlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_ENCRYPT, OnButtonEncrypt)
	ON_BN_CLICKED(IDC_BUTTON_DECRYPT, OnButtonDecrypt)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestCrypt4Dlg message handlers

BOOL CTestCrypt4Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
}

// 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 CTestCrypt4Dlg::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 CTestCrypt4Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestCrypt4Dlg::OnButtonEncrypt() 
{
	CZTeaCryptor  M;
	CCryptorTool1 CT(&M);
	CDemoData     D(&CT);

	this->UpdateData(TRUE);
	CT.GenerateKey(m_Password);
	
	strcpy( D.Name   ,m_Name1   );
	D.Code  = m_Code1    ;
	strcpy( D.IDCard, m_ID1 );
	strcpy( D.Address,m_Addr1);
	
	D.ToFile(m_FileName);
	MessageBox("加密成功","加密",MB_OK);
}

void CTestCrypt4Dlg::OnButtonDecrypt() 
{
	CZTeaCryptor  M;
	CCryptorTool1 CT(&M);
	CDemoData     D(&CT);
	
	this->UpdateData(TRUE);
	CT.GenerateKey(m_Password);
	
	
	if (D.FromFile(m_FileName)==0) {
		MessageBox("数据校验错误","解密",MB_OK|MB_ICONWARNING);
		return ;
	}
	
	m_Name2  = D.Name;
	m_Code2  = D.Code;
	m_ID2    = D.IDCard;
	m_Addr2  = D.Address;
	
	this->UpdateData(FALSE);
	MessageBox("解密成功","解密",MB_OK);
}

⌨️ 快捷键说明

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