|
这个小程序是用来作为一个非常简单的对称加密算法,比移位加密稍微强那么一点点。
seed的话大家可以自己来设置,seed大概为60位,程序没有边界检查,很简陋,希望看官们别见笑。
// Code.h: interface for the CCode class.
//
//
#if !defined(AFX_CODE_H__D5B90563_053E_4256_A61D_7D56F8FB20CF__INCLUDED_)
#define AFX_CODE_H__D5B90563_053E_4256_A61D_7D56F8FB20CF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CCode
{
public:
CString Decode(CString strCode);
CString Encode(CString strCode);
CCode();
virtual ~CCode();
private:
CString EnDeCode(CString strCode);
int iLength;
char* szSeed2;
};
#endif // !defined(AFX_CODE_H__D5B90563_053E_4256_A61D_7D56F8FB20CF__INCLUDED_)
// Code.cpp: implementation of the CCode class.
//
//
#include "stdafx.h"
#include "DecodeEncode.h"
#include "Code.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//
// Construction/Destruction
//
CCode::CCode()
{
iLength = 0;
char strTemp[60] ={0x04,0x02,0x06,0x05,0x01,0x09,0x03,0x07,0x08,0x02,\
0x04,0x02,0x06,0x05,0x01,0x09,0x03,0x07,0x08,0x02,\
0x04,0x02,0x06,0x05,0x01,0x09,0x03,0x07,0x08,0x02,\
0x04,0x02,0x06,0x05,0x01,0x09,0x03,0x07,0x08,0x02,\
0x04,0x02,0x06,0x05,0x01,0x09,0x03,0x07,0x08,0x02,\
0x04,0x02,0x06,0x05,0x01,0x09,0x03,0x07,0x08,0x02};
szSeed2 = new char[60];
memcpy(szSeed2,strTemp,60);
}
CCode::~CCode()
{
delete[] szSeed2;
}
CString CCode::Encode(CString strCode)
{
return EnDeCode(strCode);
}
CString CCode::Decode(CString strCode)
{
return EnDeCode(strCode);
}
CString CCode::EnDeCode( CString strCode )
{
LPCTSTR szSource = (LPCTSTR) strCode;
iLength = strCode.GetLength();
char *szSeed = new char[iLength];
memcpy(szSeed,szSeed2,iLength);
char * szSr = new char[iLength];
char *szDes = new char[iLength + 1];
memcpy(szSr,szSource,iLength);
for(int i = 0;i < iLength;i++)
{
szDes[i] = szSr[i] ^szSeed[i] ;
}
szDes[iLength] = '\0';
CString strTemp(szDes);
delete[] szSr;
delete[] szDes;
delete[] szSeed;
return strTemp;
} |
|