keyword.cpp

来自「1、对于凯撒密文」· C++ 代码 · 共 81 行

CPP
81
字号
// Keyword.cpp: implementation of the CKeyword class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "030300816.h"
#include "Keyword.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CKeyword::CKeyword()
{

}

CKeyword::~CKeyword()
{

}

void CKeyword::Decipher()
{
	for ( int i = 'a' ; i <= 'z' ; i ++ )
	{
		sub[m_key.GetAt(i-'a')] = i;
	}
	int length = m_cipherString.GetLength();
	CString kk = _T("");
	for ( i = 0 ; i < length ; i ++ )
	{
		char temp = m_cipherString.GetAt(i);
		if (temp >= 'a' && temp <= 'z')
		{
			kk += sub[temp];
		}
		else if (temp >= 'A' && temp <= 'Z')
		{
			kk += ( sub[temp-'A'+'a'] - 'a' + 'A');
		}
		else
		{
			kk += temp;
		}
	}
	m_plainString = kk;
}

void CKeyword::Encipher()
{
	for ( int i = 0 ; i < 26 ; i ++ )
	{
		sub['a'+i] = m_key.GetAt(i);
	}
	int length = m_plainString.GetLength();
	CString kk = _T("");
	for ( i = 0 ; i < length ; i ++ )
	{
		char temp = m_plainString.GetAt(i);
		if (temp >= 'a' && temp <= 'z')
		{
			kk += sub[temp];
		}
		else if (temp >= 'A' && temp <= 'Z')
		{
			kk += ( sub[temp-'A'+'a'] - 'a' + 'A');
		}
		else
		{
			kk += temp;
		}
	}
	m_cipherString = kk;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?