您的位置:首页 > 编程语言 > C语言/C++

c++加密解密算法用java方法替代

2015-08-05 09:48 543 查看
有两个c++文件,里面有加密,解密算法,求大神把加密,解密算法用java实现,求大神。
文件Crypt.h

#if !defined(AFX_CRYPT_H__613C5174_16F0_42A5_9493_C7489534C080__INCLUDED_)
#define AFX_CRYPT_H__613C5174_16F0_42A5_9493_C7489534C080__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CCrypt
{
static char *m_key;
public:
static CString decrypt(CString str);
static CString encrypt(CString str);
};

#endif // !defined(AFX_CRYPT_H__613C5174_16F0_42A5_9493_C7489534C080__INCLUDED_)

文件Crypt.cpp

#include "stdafx.h"
#include "crypt.h"

#include <atlconv.h>

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

//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////

char* CCrypt::m_key = "FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";

CString CCrypt::encrypt(CString str)
{
USES_CONVERSION;
int pos=str.GetLength()%strlen(m_key);
CString ret;
LPCSTR lpszAscii=T2CA(str);
for (unsigned int i=0;i<strlen(lpszAscii);i++)
{
CString tmp=ret;
ret.Format(_T("%s%03d"),tmp,(unsigned char)lpszAscii[i]^m_key[(i+pos)%strlen(m_key)]);
}
return ret;
}

CString CCrypt::decrypt(CString str)
{
USES_CONVERSION;

LPCSTR lpszAscii=T2CA(str);
int pos=(strlen(lpszAscii)/3)%strlen(m_key);
CString ret;
char buffer[4];
buffer[3]=0;
for (unsigned int i=0;i<strlen(lpszAscii)/3;i++)
{
memcpy(buffer,lpszAscii+i*3,3);
TCHAR tmp[2];
tmp[1]=0;
tmp[0]=atoi(buffer)^m_key[(i+pos)%strlen(m_key)];
ret+=tmp;
}
return ret;
} 阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: