1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
   |  
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <cstring.h>
using namespace std;
 
class CSecurity
{
 
  public:  
 
   CString CSecurity::Crypt(LPCSTR p_lpszTerm)
   {
    	CString strTerm = p_lpszTerm;
    	//strTerm.MakeUpper();
    	LPSTR lpczCursor = (LPSTR) (LPCSTR) strTerm;
    	CString strCrytedTerm;
    	CString strByte;
 
    	int nLength = strTerm.GetLength();
    	int nCounter = 3;
    	int nOffset;
    	int nRotation;
    	unsigned char cCrypted;
    	while (*lpczCursor)
    	{	
    		cCrypted = *lpczCursor++;
 
    		nOffset = m_pOffsetTable[nCounter++ % m_nOffsetTableSize];
    		nRotation = m_pOffsetTable[nCounter++ % m_nOffsetTableSize];
    		//cCrypted = RotLeft(cCrypted,nRotation);
     		cCrypted += nOffset;
 
    		//strByte.Format("%.2X",cCrypted);
    		strCrytedTerm += strByte;
    	}
    	strCrytedTerm = Scramble(strCrytedTerm);
    	return strCrytedTerm;
    }
    //static int DefaultOffsetTable[] = {5,9,2,6,5,3,5,9,1,4,1,5,9,2,6,5,3,5,9,1};
 
    CSecurity::CSecurity()
    {
		 int DefaultOffsetTable[] = {5,9,2,6,5,3,5,9,1,4,1,5,9,2,6,5,3,5,9,1};
         SetOffsetTable(DefaultOffsetTable,20);
    }
 
    private :
 
    CString CSecurity::Scramble(LPCSTR p_lpszTerm)
    {
    		 CString strTerm = p_lpszTerm;
    		 int nMidPoint = strTerm.GetLength()/2;
    		 CString strLeft = strTerm.Left(nMidPoint);
    		 CString strRight = strTerm.Mid(nMidPoint);
 
    		 CString strScrambled;
    		 LPSTR lpszLeftCursor = (LPSTR) (LPCSTR) strLeft;
    		 LPSTR lpszRightCursor = (LPSTR) (LPCSTR) strRight;
    		 while ((*lpszLeftCursor) && (*lpszRightCursor))
    		 {
    		 		 if (*lpszRightCursor)
    		 		 		 strScrambled += *lpszRightCursor++;
    		 		 if (*lpszLeftCursor)
    		 		 		 strScrambled += *lpszLeftCursor++;
    		 }
    		 return strScrambled;
    }
 
    inline void CSecurity::SetOffsetTable(int* p_pOffsetTable, int p_nTableSize)
    {
    		 m_pOffsetTable = p_pOffsetTable;
    		 m_nOffsetTableSize = p_nTableSize;
    }
 
    int* m_pOffsetTable;
    int  m_nOffsetTableSize; 
};
 
int main()
{
    CSecurity Test;
    Test.CSecurity::Crypt("test");
    return(0);
} | 
Partager