keyencryption.cpp
来自「VC环境下BlowFish算法加密解密原程序.This is a simple 」· C++ 代码 · 共 101 行
CPP
101 行
// 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 + =
减小字号Ctrl + -
显示快捷键?