📄 keyword_cipher.cpp
字号:
// KeyWord_Cipher.cpp : implementation file
//
#include "stdafx.h"
#include "MY_CAP.h"
#include "KeyWord_Cipher.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKeyWord_Cipher dialog
CMY_CAPDlg *Main_CapK;
CKeyWord_Cipher::CKeyWord_Cipher(CWnd* pParent /*=NULL*/)
: CDialog(CKeyWord_Cipher::IDD, pParent)
{
//{{AFX_DATA_INIT(CKeyWord_Cipher)
m_KeyWord = _T("");
//}}AFX_DATA_INIT
}
void CKeyWord_Cipher::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKeyWord_Cipher)
DDX_Text(pDX, IDC_KEYWORD, m_KeyWord);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKeyWord_Cipher, CDialog)
//{{AFX_MSG_MAP(CKeyWord_Cipher)
ON_COMMAND(IDD_ENCIPHER, OnEncipher)
ON_COMMAND(IDD_DECIPHER, OnDecipher)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeyWord_Cipher message handlers
void CKeyWord_Cipher::OnEncipher()
{
// TODO: Add your command handler code here
UpdateData(TRUE);
Main_CapK->UpdateData(TRUE);
m_Plaintext = Main_CapK->m_Plaintext;
m_RKeyWord = UpdatePhrase(m_KeyWord);
m_RKeyWord = Produce_Cipher(m_RKeyWord);
m_Ciphertext = Produce_Cipher(m_Plaintext,0);
Main_CapK->m_Ciphertext = m_Ciphertext;
Main_CapK->UpdateData(FALSE);
if (Main_CapK ->m_Ciphertext.GetLength () != 0)
Main_CapK -> OnSave_Ciphertext ();
}
void CKeyWord_Cipher::OnDecipher()
{
// TODO: Add your command handler code here
UpdateData(TRUE);
Main_CapK->UpdateData(TRUE);
m_Ciphertext = Main_CapK->m_Ciphertext;
m_RKeyWord = UpdatePhrase(m_KeyWord);
m_RKeyWord = Produce_Cipher(m_RKeyWord);
m_Plaintext = Produce_Cipher(m_Ciphertext,1);
Main_CapK->m_Plaintext = m_Plaintext;
Main_CapK->UpdateData(FALSE);
if (Main_CapK ->m_Plaintext.GetLength () != 0)
Main_CapK -> OnSave_Plaintext ();
}
CString CKeyWord_Cipher::UpdatePhrase(CString phrase)
{
CString Phrase,temp;
int i = 0;
while( i < phrase.GetLength() )
{
if(phrase[i] >= 'a' && phrase[i] <= 'z')
temp = phrase[i];
else if( phrase[i] >= 'A' && phrase[i] <= 'Z' )
temp = phrase - 'A' + 'a';
else
{
i++;
continue;
}
if( Phrase.FindOneOf(temp) == -1 ) Phrase += phrase[i];
i++;
}
return Phrase;
}
CString CKeyWord_Cipher::Produce_Cipher(CString phrase)
{
CString Ciphertext,temp;
int i = 0;
Ciphertext = phrase;
while( i <= 25 )
{
temp = 'a' + i;
if( Ciphertext.FindOneOf(temp) == -1 )
{
Ciphertext += temp;
}
i++;
}
return Ciphertext;
}
CString CKeyWord_Cipher::Produce_Cipher(CString text, int choice)
{
CString Text,temp;
int i = 0;
if( choice == 0 ) //EnCipher
{
while( i < text.GetLength() )
{
if( text[i] >= 'a' && text[i] <= 'z')
{
Text += m_RKeyWord[text[i]-'a'];
}
else if( text[i] >= 'A' && text[i] <= 'Z' )
{
Text += m_RKeyWord[text[i]-'A'];
}
/* else
{
Text += text[i];
}*/
i++;
}
}
else if( choice == 1 ) //DeCipher
{
while( i < text.GetLength() )
{
if( text[i] >= 'a' && text[i] <= 'z')
{
temp = text[i];
Text += m_RKeyWord.FindOneOf(temp)+'a';
}
else if( text[i] >= 'A' && text[i] <= 'Z' )
{
temp = text[i] - 'A' + 'a';
Text += m_RKeyWord.FindOneOf(temp)+'a';
}
/* else
{
Text += text[i];
}*/
i++;
}
}
return Text;
}
void CKeyWord_Cipher::Trans_Dialog(CWnd *temp)
{
Main_CapK = (CMY_CAPDlg *)temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -