www.pudn.com > endecipher.rar > Dlg_Playfair.cpp


// Dlg_Playfair.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Cipher.h" 
#include "Dlg_Playfair.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlg_Playfair dialog 
 
char key[5][5]; 
 
class Position{ 
public: 
	int row; 
	int col; 
}; 
 
CDlg_Playfair::CDlg_Playfair(CWnd* pParent /*=NULL*/) 
	: CDialog(CDlg_Playfair::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CDlg_Playfair) 
	m_key = _T(""); 
	m_t = 0; 
	m_setkey = _T("firewall security"); 
	m_cfpath = _T(""); 
	m_cstring = _T(""); 
	m_pfpath = _T(""); 
	m_pstring = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
BOOL CDlg_Playfair::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
	OnButtonSetkey(); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CDlg_Playfair::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CDlg_Playfair) 
	DDX_Control(pDX, IDC_EDIT_PSTRING, m_ps); 
	DDX_Control(pDX, IDC_EDIT_PFPATH, m_pfp); 
	DDX_Control(pDX, IDC_EDIT_CSTRING, m_cs); 
	DDX_Control(pDX, IDC_EDIT_CFPATH, m_cfp); 
	DDX_Control(pDX, IDC_STATIC_SP, m_sp); 
	DDX_Control(pDX, IDC_STATIC_SC, m_sc); 
	DDX_Control(pDX, IDC_STATIC_FP, m_fp); 
	DDX_Control(pDX, IDC_STATIC_FC, m_fc); 
	DDX_Control(pDX, IDC_STATIC_File, m_file); 
	DDX_Control(pDX, IDC_STATIC_String, m_string); 
	DDX_Control(pDX, IDC_BUTTON_OPENPF, m_openpf); 
	DDX_Control(pDX, IDC_BUTTON_OPENCF, m_opencf); 
	DDX_Text(pDX, IDC_EDIT_Key, m_key); 
	DDX_Radio(pDX, IDC_RADIO_S, m_t); 
	DDX_Text(pDX, IDC_EDIT_SET, m_setkey); 
	DDX_Text(pDX, IDC_EDIT_CFPATH, m_cfpath); 
	DDX_Text(pDX, IDC_EDIT_CSTRING, m_cstring); 
	DDX_Text(pDX, IDC_EDIT_PFPATH, m_pfpath); 
	DDX_Text(pDX, IDC_EDIT_PSTRING, m_pstring); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CDlg_Playfair, CDialog) 
	//{{AFX_MSG_MAP(CDlg_Playfair) 
	ON_BN_CLICKED(IDC_RADIO_S, OnRadioS) 
	ON_BN_CLICKED(IDC_RADIO_F, OnRadioF) 
	ON_BN_CLICKED(IDC_BUTTON_OPENPF, OnButtonOpenpf) 
	ON_BN_CLICKED(IDC_BUTTON_OPENCF, OnButtonOpencf) 
	ON_BN_CLICKED(IDC_BUTTON_SETKEY, OnButtonSetkey) 
	ON_BN_CLICKED(IDC_BUTTON_Encipher, OnBUTTONEncipher) 
	ON_BN_CLICKED(IDC_BUTTON_Decipher, OnBUTTONDecipher) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlg_Playfair message handlers 
 
void CDlg_Playfair::OnRadioS()  
{ 
	// TODO: Add your control notification handler code here 
	m_t=0; 
	m_sp.EnableWindow(true); 
	m_sc.EnableWindow(true); 
	m_string.EnableWindow(true); 
	m_ps.EnableWindow(true); 
	m_cs.EnableWindow(true); 
 
	m_pfp.EnableWindow(false); 
	m_cfp.EnableWindow(false); 
	m_file.EnableWindow(false); 
	m_openpf.EnableWindow(false); 
	m_opencf.EnableWindow(false); 
	m_fc.EnableWindow(false); 
	m_fp.EnableWindow(false); 
	UpdateData(true); 
	m_cfpath=""; 
	m_pfpath=""; 
	UpdateData(false); 
} 
 
void CDlg_Playfair::OnRadioF()  
{ 
	// TODO: Add your control notification handler code here 
	m_t=1; 
	m_sp.EnableWindow(false); 
	m_sc.EnableWindow(false); 
	m_string.EnableWindow(false); 
	m_ps.EnableWindow(false); 
	m_cs.EnableWindow(false); 
 
	m_pfp.EnableWindow(true); 
	m_cfp.EnableWindow(true); 
	m_file.EnableWindow(true); 
	m_openpf.EnableWindow(true); 
	m_opencf.EnableWindow(true); 
	m_fc.EnableWindow(true); 
	m_fp.EnableWindow(true); 
	UpdateData(true); 
	m_cstring=""; 
	m_pstring=""; 
	UpdateData(false); 
} 
 
void CDlg_Playfair::OnButtonOpenpf()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(true); 
	file.Path(m_pfpath); 
	UpdateData(false); 
} 
 
void CDlg_Playfair::OnButtonOpencf()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(true); 
	file.Path(m_cfpath); 
	UpdateData(false); 
} 
 
char * Change(CString a) 
{ 
	char *b; 
	int i,j,n; 
	n=strlen(a); 
	b=new char [n+1]; 
	j=0; 
	for(i=0;i<=n-1;i++) 
	{ 
		if(isupper(a[i])) 
			b[j++]=a[i]-'A'; 
		else if(islower(a[i])) 
			b[j++]=a[i]; 
		else 
			; 
	} 
	b[j]='\0'; 
	return b; 
} 
 
void CDlg_Playfair::OnButtonSetkey() /* 根据密钥设置密钥矩阵 */ 
{ 
	// TODO: Add your control notification handler code here 
	bool b[26]; 
	char *c; 
	int i,j,n,s; 
	for(i=0;i<=25;i++) 
		b[i]=true; 
	UpdateData(true); 
	c=Change(m_setkey); 
	n=strlen(c); 
	s=0; 
	for(i=0;i