www.pudn.com > CipherSystem.rar > PlayFairProcess.cpp


// PlayFairProcess.cpp : 实现文件 
// 
 
#include "stdafx.h" 
#include "CipherSystem.h" 
#include "PlayFairProcess.h" 
#include ".\playfairprocess.h" 
#include "PlayFairCipherSystem.h" 
#include "GlobalFunctions.h" 
 
// PlayFairProcess 对话框 
 
IMPLEMENT_DYNAMIC(PlayFairProcess, CDialog) 
PlayFairProcess::PlayFairProcess(CWnd* pParent /*=NULL*/) 
	: CDialog(PlayFairProcess::IDD, pParent) 
	, m_strKey(_T("")) 
	, m_strShow(_T("")) 
	, m_iMark(0) 
{ 
} 
 
PlayFairProcess::~PlayFairProcess() 
{ 
} 
 
void PlayFairProcess::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	DDX_Text(pDX, IDC_EDIT1, m_strKey); 
	DDX_Text(pDX, IDC_STATIC_SHOW, m_strShow); 
} 
 
 
BEGIN_MESSAGE_MAP(PlayFairProcess, CDialog) 
	ON_BN_CLICKED(ID_PF_ENCRYPT, OnBnClickedPfEncrypt) 
	ON_BN_CLICKED(ID_PF_DECRYPT, OnBnClickedPfDecrypt) 
	ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel) 
	ON_BN_CLICKED(IDC_BUTTON_SHOW, OnBnClickedButtonShow) 
END_MESSAGE_MAP() 
 
 
// PlayFairProcess 消息处理程序 
 
void PlayFairProcess::OnBnClickedPfEncrypt() 
{ 
	// TODO: 在此添加控件通知处理程序代码 
	UpdateData(TRUE); 
	if (m_strKey.IsEmpty()) 
	{ 
		AfxMessageBox("请输入密钥"); 
		return; 
	} 
	m_iMark = 1; 
	OnOK(); 
} 
 
void PlayFairProcess::OnBnClickedPfDecrypt() 
{ 
	// TODO: 在此添加控件通知处理程序代码 
	UpdateData(TRUE); 
	if (m_strKey.IsEmpty()) 
	{ 
		AfxMessageBox("请输入密钥"); 
		return; 
	} 
	m_iMark = -1; 
	OnOK(); 
} 
 
void PlayFairProcess::OnBnClickedCancel() 
{ 
	// TODO: 在此添加控件通知处理程序代码 
	m_iMark = 0; 
	OnCancel(); 
} 
 
void PlayFairProcess::OnBnClickedButtonShow() 
{ 
	// TODO: 在此添加控件通知处理程序代码 
	UpdateData(TRUE); 
	if (m_strKey.IsEmpty()) 
	{ 
		AfxMessageBox("请输入密钥"); 
		return; 
	} 
 
	PlayFairEncryptSystem mySystem; 
 
	string key; 
	CStringToString(this->m_strKey, key); 
	mySystem.GetKey(key); 
 
	this->m_strShow = "the key matrix is:\n\n"; 
	int i; 
	for (i=0; i<5; i++) 
	{ 
		int j; 
		for (j=0; j<5; j++)  
		{ 
			m_strShow += mySystem.encryptMatrix[i][j]; 
			m_strShow += "  "; 
		} 
		m_strShow += '\n'; 
	} 
	UpdateData(FALSE); 
}