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

📄 caesardlg.cpp

📁 包涵了密码学教程里面的大部分加密算法
💻 CPP
字号:
// CaesarDlg.cpp : implementation file
//

#include "stdafx.h"
#include <stdio.h>
#include "Crypt.h"
#include "CaesarDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCaesarDlg dialog


CCaesarDlg::CCaesarDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCaesarDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCaesarDlg)
	m_strPlainText = _T("");
	m_strCipher = _T("");
	//}}AFX_DATA_INIT
}


void CCaesarDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCaesarDlg)
	DDX_Text(pDX, IDC_PlainText, m_strPlainText);
	DDX_Text(pDX, IDC_Cipher, m_strCipher);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCaesarDlg, CDialog)
	//{{AFX_MSG_MAP(CCaesarDlg)
	ON_BN_CLICKED(IDC_Decrypt, OnDecrypt)
	ON_BN_CLICKED(IDC_Encrypt, OnEncrypt)
	ON_EN_CHANGE(IDC_PlainText, OnChangePlainText)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaesarDlg message handlers

void CCaesarDlg::OnDecrypt() 
{
	// TODO: Add your control notification handler code here
	int i;
	int m_iLen;
	CString m_Cipher, m_strTemp;
	
	//得到编辑框中内容,即密文
	UpdateData(true);
	m_Cipher = m_strCipher;
	m_iLen = m_strCipher.GetLength();
	char* m_chTemp = new char[m_iLen];
	m_chTemp = m_strCipher.GetBuffer(0);
	//执行Caesar解密算法
	for(i=0; i<m_iLen; i++)
		m_chTemp[i] -= 3;
	m_strTemp.Format("%s", m_chTemp);
	m_strPlainText = m_strTemp;
	m_strCipher = m_Cipher;
	//将解密后的字符串,即明文显示
	UpdateData(false);
}

void CCaesarDlg::OnEncrypt() 
{
	// TODO: Add your control notification handler code here
	int i;
	int	m_iLen;
	CString	m_PlainText, m_strTemp;	

	//得到CEditCtrl中需要加密的字符串
	UpdateData(true);
	m_PlainText = m_strPlainText;
	//得到明文的长度
	m_iLen = m_strPlainText.GetLength();
	//将明文字符串转换为char类型
	char *m_cTemp = new char[m_iLen];
	m_cTemp = m_strPlainText.GetBuffer(0);

	//执行Caesar加密体制
	for(i=0; i<m_iLen; i++)
		m_cTemp[i] += 3;

	//将char类型密文转换为字符串类型
	m_strTemp.Format("%s", m_cTemp);
	//AfxMessageBox(m_strTemp);
	//将密文字符串赋给相应对话框变量
	m_strCipher = m_strTemp;
	m_strPlainText = m_PlainText;
	//显示加密字符串密文
	UpdateData(false);
}

void CCaesarDlg::OnChangePlainText() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here

	//控制输入字符只能为字母
	char ch;

	UpdateData(true);	
	ch = getchar();
	//AfxMessageBox(ch);
	if((ch>65 && ch<90) || (ch>97 && ch<122))
		putchar(ch);
	UpdateData(false);

	/*
	int i, count=0;
	int m_iLen;

	UpdateData(true);
	AfxMessageBox(m_strPlainText);
	m_iLen = m_strPlainText.GetLength();
	char* m_chTemp = new char[m_iLen];
	char* m_chPlainText = new char[m_iLen];
	for(i=0; i<m_iLen; i++)
	{
		if((65<m_chTemp[i] && m_chTemp[i]<90) || (97<m_chTemp[i] && m_chTemp[i]<122))
		{			
			m_chPlainText[count] = m_chTemp[i];
			count ++;
		}
	}
    
	m_strPlainText.Format("%s", m_chPlainText);
	UpdateData(false);
	*/
}

⌨️ 快捷键说明

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