www.pudn.com > CipherSystem.rar > CaeserCipherSystem.cpp


#include "stdafx.h" 
#include "CaeserCipherSystem.h" 
 
 
////////////////////////////////////////////////////////////////////////////////////// 
////////////////        Implement class of CaeserEncryptSystem      ////////////////// 
////////////////////////////////////////////////////////////////////////////////////// 
 
bool CaeserEncryptSystem::GetKey(int key) 
{ 
	this->shiftKey = key; 
	return true; 
} 
 
void CaeserEncryptSystem::Encrypt() 
{ 
	int i; 
	for (i=0; i<(int)text.length(); i++) 
	{ 
		text[i] = char((int(text[i] - 97) + shiftKey) % 26 + 97); 
	} 
 
	return; 
} 
 
void CaeserEncryptSystem::Decrypt() 
{ 
	int i; 
	for (i=0; i<(int)text.length(); i++) 
	{ 
		text[i] = char((int(text[i] - 97) + 26 - shiftKey) % 26 + 97); 
	} 
 
	return; 
}