📄 caeser_cipher.cpp
字号:
// aeser_Cipher.cpp : implementation file
//
#include "stdafx.h"
#include "MY_CAP.h"
#include "Caeser_Cipher.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Caeser_Cipher dialog
CMY_CAPDlg *Main_CapC;
CCaeser_Cipher::CCaeser_Cipher(CWnd* pParent /*=NULL*/)
: CDialog(CCaeser_Cipher::IDD, pParent)
{
//{{AFX_DATA_INIT(Caeser_Cipher)
m_Value_Shift = 0;
//}}AFX_DATA_INIT
}
void CCaeser_Cipher::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Caeser_Cipher)
DDX_Text(pDX, IDC_Value_Shift, m_Value_Shift);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCaeser_Cipher, CDialog)
//{{AFX_MSG_MAP(Caeser_Cipher)
ON_COMMAND(IDD_ENCIPHER, OnEncipher)
ON_COMMAND(IDD_DECIPHER, OnDecipher)
ON_COMMAND(IDD_QUIT, OnQuit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Caeser_Cipher message handlers
void CCaeser_Cipher::Trans_Dialog(CWnd *temp)
{
Main_CapC = (CMY_CAPDlg *)temp;
}
void CCaeser_Cipher::OnEncipher()
{
// TODO: Add your command handler code here
Main_CapC->UpdateData(TRUE);
UpdateData(TRUE);
m_Ciphertext = "";
m_Plaintext = Main_CapC->m_Plaintext;
if( m_Plaintext != "" )
{
m_Ciphertext = translation(m_Plaintext,m_Value_Shift);
Main_CapC -> m_Ciphertext = m_Ciphertext;
Main_CapC -> UpdateData(FALSE);
if (Main_CapC -> m_Ciphertext.GetLength () != 0)
Main_CapC -> OnSave_Ciphertext();
}
}
void CCaeser_Cipher::OnDecipher()
{
// TODO: Add your command handler code here
UpdateData(TRUE);
m_Plaintext = "";
m_Ciphertext = Main_CapC->m_Ciphertext;
if( m_Ciphertext != "" )
{
m_Plaintext = translation(m_Ciphertext,26-m_Value_Shift);
Main_CapC -> m_Plaintext = m_Plaintext;
Main_CapC -> UpdateData(FALSE);
if (Main_CapC -> m_Plaintext.GetLength () != 0)
Main_CapC -> OnSave_Plaintext();
}
}
CString CCaeser_Cipher::translation(CString plaintext, int Value_Shift)
{
int i=0;
CString Ciphertext;
while ( i < plaintext.GetLength() )
{
if( plaintext[i] >= 'a' && plaintext[i] <= 'z' )
{
Ciphertext += ((plaintext[i]-'a'+Value_Shift)%26+'a');
}
else if( plaintext[i] >= 'A' && plaintext[i] <= 'Z' )
{
Ciphertext += ((plaintext[i]-'A'+Value_Shift)%26+'a');
}
/* else
{
Ciphertext += plaintext[i];
}*/
i++;
}
return Ciphertext;
}
void CCaeser_Cipher::OnQuit()
{
// TODO: Add your command handler code here
OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -