📄 keyencryption.cpp
字号:
// KeyEncryption.cpp: implementation of the CChanger class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "KeyEncryption.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CKeyEncryption::CKeyEncryption()
{
}
CKeyEncryption::~CKeyEncryption()
{
}
string CKeyEncryption::Encrypt(string recVal, string recKey)
{
int tmpVal1,tmpVal2,tmpVal3,mKeyLen,mCounter,KeyCount,DataLen;
DataLen=recVal.length();
string tmp_recVal=recVal;
char tChar;
mKeyLen=recKey.length();
DataLen=recVal.length()-1;
KeyCount=0;
for(mCounter=0; mCounter<=DataLen; mCounter++)
{
if(KeyCount==0)
{
tmpVal1=recVal.at(mCounter);
tmpVal2=recKey.at(KeyCount);
tmpVal3=recKey.at(mKeyLen-1);
tmpVal1=(tmpVal1+30)+(tmpVal3%10);
}
else
{
tmpVal1=recVal.at(mCounter);
tmpVal2=recKey.at(KeyCount);
tmpVal3=recKey.at(KeyCount-1);
tmpVal1=(tmpVal1+30)+(tmpVal3%10);
}
tChar=tmpVal1;
tmp_recVal.at(mCounter)=tChar;
KeyCount++;
if(KeyCount==(mKeyLen-1)) KeyCount=0;
}
return tmp_recVal;
}
string CKeyEncryption::Decrypt(string recVal, string recKey)
{
int tmpVal1,tmpVal2,tmpVal3,mKeyLen,mCounter,KeyCount,DataLen;
DataLen=recVal.length();
string tmp_recVal=recVal;
char tChar;
mKeyLen=recKey.length();
DataLen=recVal.length()-1;
KeyCount=0;
for(mCounter=0; mCounter<=DataLen; mCounter++)
{
if(KeyCount==0)
{
tmpVal1=recVal.at(mCounter);
tmpVal2=recKey.at(KeyCount);
tmpVal3=recKey.at(mKeyLen-1);
tmpVal1=(tmpVal1-30)-(tmpVal3%10);
}
else
{
tmpVal1=recVal.at(mCounter);
tmpVal2=recKey.at(KeyCount);
tmpVal3=recKey.at(KeyCount-1);
tmpVal1=(tmpVal1-30)-(tmpVal3%10);
}
tChar=tmpVal1;
tmp_recVal.at(mCounter)=tChar;
KeyCount++;
if(KeyCount==(mKeyLen-1)) KeyCount=0;
}
return tmp_recVal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -