Home  >  Article  >  WeChat Applet  >  Introduction to implementing MFC’s simple encryption and decryption applet

Introduction to implementing MFC’s simple encryption and decryption applet

高洛峰
高洛峰Original
2017-03-24 13:50:172619browse

简单的加密解密算法

       这个小程序是用来作为一个非常简单的对称加密算法,比移位加密稍微强那么一点点。

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] = &#39;\0&#39;; 

    CString strTemp(szDes); 
    delete[] szSr; 
    delete[] szDes; 
    delete[] szSeed; 
  
    return strTemp;   
}

整个程序使用起来很简单,就是调用一下加密解密就行了。

The above is the detailed content of Introduction to implementing MFC’s simple encryption and decryption applet. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn