📄 column_permutation.cpp
字号:
// Column_permutation.cpp : implementation file
//
#include "stdafx.h"
#include "cryptology.h"
#include "Column_permutation.h"
#include "colum_permu.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char text[N];
char key[N];
/////////////////////////////////////////////////////////////////////////////
// CColumn_permutation property page
IMPLEMENT_DYNCREATE(CColumn_permutation, CPropertyPage)
CColumn_permutation::CColumn_permutation() : CPropertyPage(CColumn_permutation::IDD)
{
//{{AFX_DATA_INIT(CColumn_permutation)
m_ciphertext = _T("");
m_key = _T("");
m_plaintext = _T("");
//}}AFX_DATA_INIT
}
CColumn_permutation::~CColumn_permutation()
{
}
void CColumn_permutation::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CColumn_permutation)
DDX_Text(pDX, IDC_CIPHERTEXT, m_ciphertext);
DDX_Text(pDX, IDC_KEY, m_key);
DDX_Text(pDX, IDC_PLAINTEXT, m_plaintext);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CColumn_permutation, CPropertyPage)
//{{AFX_MSG_MAP(CColumn_permutation)
ON_BN_CLICKED(IDC_ENCRY, OnEncry)
ON_BN_CLICKED(IDC_DECRY, OnDecry)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColumn_permutation message handlers
void CColumn_permutation::OnEncry()
{
UpdateData();
Column cp;
int len,lens,i;
len=m_plaintext.GetLength();
lens=m_key.GetLength();
for(i=0;i<len;i++){
text[i]=m_plaintext[i];
}
for(i=0;i<lens;i++){
key[i]=m_key[i];
}
//cout<<"input the key:";
//cin>>key;
//cout<<"input the plaintext:";
//cin>>text;
cp.encipher(key,text);
m_ciphertext.Format("%s",text);
//cout<<"cipertext:";
//cp.text_print();
//cp.decipher(key,text);
//cout<<"plaintext:";
//cp.text_print();
UpdateData(false);
if(MessageBox("是否保存密文?",NULL,MB_OKCANCEL)==IDOK)
{
SaveFile();
}
}
void CColumn_permutation::OnDecry()
{
UpdateData();
Column cp;
int len,lens,i;
len=m_plaintext.GetLength();
lens=m_key.GetLength();
for(i=0;i<lens;i++){
key[i]=m_key[i];
}
//cout<<"input the key:";
//cin>>key;
//cout<<"input the plaintext:";
//cin>>text;
//cp.encipher(key,text);
//m_ciphertext.Format("%s",text);
//cout<<"cipertext:";
//cp.text_print();
cp.decipher(key,text);
m_plaintext.Format("%s",text);
//cout<<"plaintext:";
//cp.text_print();
UpdateData(false);
}
void CColumn_permutation::SaveFile()
{
CFileDialog dlg(false);
if(dlg.DoModal()==IDOK)
{
m_filename=dlg.GetPathName();
int len=m_filename.GetLength();
char *filename=new char[len];
filename=m_filename.GetBuffer(len);
m_file.Open(filename,CFile::modeWrite |CFile::modeCreate);
len=m_ciphertext.GetLength();
char *buf=new char[len];
buf=m_ciphertext.GetBuffer(len);
m_file.Write(buf,len);
m_file.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -