// ------------------------------------------------------------------------------------------------------------------------------------------------------// - Miscellaneous. -// ------------------------------------------------------------------------------------------------------------------------------------------------------using namespace std;#pragma once
// ------------------------------------------------------------------------------------------------------------------------------------------------------// - Header(s). -// ------------------------------------------------------------------------------------------------------------------------------------------------------#include
// ------------------------------------------------------------------------------------------------------------------------------------------------------// - Miscellaneous. -// ------------------------------------------------------------------------------------------------------------------------------------------------------inline const size_t GetSubString(const CString cstrSource, CString &cstrTarget, CONST UINT uPart2Lookup, const TCHAR cDelim)// Get substring no. uPart2Lookup of cstrSource and place it in cstrTarget. Substrings are separated by cDelim. Return length of substring.{ TRY { if(cstrSource.IsEmpty()) // No work to do. return 0; cstrTarget.Empty(); int iLoc_Begin = -1, iLoc_End = -1; if(uPart2Lookup == 0) { if(cstrSource[0] != cDelim) { iLoc_Begin = 0; iLoc_End = cstrSource.Find(cDelim, 1); } } else { for(UINT uPart = 0; uPart < iloc_begin =" cstrSource.Find(cDelim," iloc_end =" cstrSource.Find(cDelim," iloc_begin ="="" iloc_end ="="" iloc_end =" cstrSource.GetLength();" cstrtarget =" cstrSource.Mid(iLoc_Begin," cdelim =" TCHAR(''))//" n =" 3210" idigit =" ::_wtoi(CString(cstrlX[cstrlX.GetLength()" are ="="" iencryptdecryptstandard =" eTEA," ukey =" MAGIC_KEY)" m_iencryptdecryptstandard ="="" ullength =" (ULONG)cstrVal.GetLength();" ulid =" 0;" ullength =" 2L" ulid =" 0;" m_iencryptdecryptstandard ="=" ulid =" 0;" ulid =" 0;" ival =" (int)GetVec(0L);" chval =" (TCHAR)GetVec(0L);" m_iencryptdecryptstandard ="=" uid =" 0;" uid =" 0;" m_iencryptdecryptstandard ="=" uid =" 0;" uid =" 0;" uid =" 0;" cstrcommasepvalues =" cstrCommaSepValue;" chstop =" NULL;" uid =" 0;" cstrcommasepvalue =" ::GetSubString(cstrCommaSepValues," cstrcommasepvalue =" cstrCommaSepValue.Trim();" ulval =" ::wcstoul(cstrCommaSepValue," ulval ="=" ulval ="=" m_iencryptdecryptstandard =" iEncryptDecryptStandard;" ioffset =" 0)" ioffset =" 0)" href="http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm">http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm. { ULONG ulSum = 0; ULONG ulVec[SIZE_OF_VEC_TEA] = { GetVec(iOffset + 0), GetVec(iOffset + 1) }; for(register int iBit = 0; iBit <>> 5) + m_uKey[1]); ulVec[1] += ((ulVec[0] <<>> 5) + m_uKey[3]); } SetVec(iOffset + 0, ulVec[0]); SetVec(iOffset + 1, ulVec[1]); } inline const void TEADecrypt(const int iOffset) // Core decryption method (TEA) inspired from http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm. { ULONG ulSum = 0xc6ef3720; ULONG ulVec[SIZE_OF_VEC_TEA] = { GetVec(iOffset + 0), GetVec(iOffset + 1) }; for(register int iBit = 0; iBit <>> 5) + m_uKey[3]); ulVec[0] -= ((ulVec[1] <<>> 5) + m_uKey[1]); ulSum -= m_ulDelta; } SetVec(iOffset + 0, ulVec[0]); SetVec(iOffset + 1, ulVec[1]); } // ******************** // * XTEA. * // ******************** inline const void XTEAEncrypt(const int iOffset, CONST ULONG ulNumRounds = 32) // Core encryption method (XTEA) inspired from http://en.wikipedia.org/wiki/XTEA. { ULONG ulSum = 0L; ULONG ulVec[SIZE_OF_VEC_TEA] = { GetVec(iOffset + 0), GetVec(iOffset + 1) }; for(register ULONG ulRound = 0L; ulRound <>> 5)) + ulVec[1]) ^ (ulSum + m_uKey[ulSum & 3]); ulSum += m_ulDelta; ulVec[1] += (((ulVec[0] <<>> 5)) + ulVec[0]) ^ (ulSum + m_uKey[(ulSum >> 11) & 3]); } SetVec(iOffset + 0, ulVec[0]); SetVec(iOffset + 1, ulVec[1]); } inline const void XTEADecrypt(const int iOffset, CONST ULONG ulNumRounds = 32) // Core decryption method (XTEA) inspired from http://en.wikipedia.org/wiki/XTEA. { ULONG ulSum = m_ulDelta * ulNumRounds; ULONG ulVec[SIZE_OF_VEC_TEA] = { GetVec(iOffset + 0), GetVec(iOffset + 1) }; for(register ULONG ulRound = 0L; ulRound <>> 5)) + ulVec[0]) ^ (ulSum + m_uKey[(ulSum >> 11) & 3]); ulSum -= m_ulDelta; ulVec[0] -= (((ulVec[1] <<>> 5)) + ulVec[1]) ^ (ulSum + m_uKey[ulSum & 3]); } SetVec(iOffset + 0, ulVec[0]); SetVec(iOffset + 1, ulVec[1]); } // ******************** // * XXTEA. * // ******************** #define MX ((ulVecLast >> 5 ^ ulVecFirst <<>> 3 ^ ulVecLast << href="http://en.wikipedia.org/wiki/XXTEA">http://en.wikipedia.org/wiki/XXTEA { LONG lN = (LONG)GetVecSize(); ULONG *ulVec = new ULONG[lN]; ::memset(ulVec, 0, lN * sizeof(ULONG)); for(int iId = 0; iId < ule =" 0L," ulround =" 0L," ulsum =" 0L," ulveclast =" ulVec[lN" ulvecfirst =" ulVec[0];" lq =" 6"> 0) { ulSum += m_ulDelta; ulE = (ulSum >> 2) & 3; for(ulRound = 0L; ulRound < (ULONG)lN - 1L; ulRound++) { ulVecFirst = ulVec[ulRound + 1]; ulVecLast = ulVec[ulRound] += MX; } ulVecFirst = ulVec[0]; ulVecLast = ulVec[lN - 1] += MX; } // Copy from local vec. for(int iId = 0; iId < href="http://en.wikipedia.org/wiki/XXTEA">http://en.wikipedia.org/wiki/XXTEA { LONG lN = (LONG)GetVecSize(); ULONG *ulVec = new ULONG[lN]; ::memset(ulVec, 0, lN * sizeof(ULONG)); for(int iId = 0; iId < ule =" 0L," ulround =" 0L," ulsum =" 0L," ulveclast =" ulVec[lN" ulvecfirst =" ulVec[0];" lq =" 6" ulsum =" lQ" ule =" (ulSum">> 2) & 3; for(ulRound = (ULONG)lN - 1L; ulRound > 0L; ulRound--) { ulVecLast = ulVec[ulRound - 1]; ulVecFirst = ulVec[ulRound] -= MX; } ulVecLast = ulVec[lN - 1]; ulVecFirst = ulVec[0] -= MX; ulSum -= m_ulDelta; } // Copy from local vec. for(int iId = 0; iId < ulcoord =" m_ulvecEncrypt.at(uId);">::size_type stSize = m_ulvecEncrypt.size(); return stSize; } inline void SetVec(ULONG uId, ULONG ulVal) { m_ulvecEncrypt.at(uId) = ulVal; } private: // 0. Properties. (alphabetical). EEncryptDecryptStandard m_iEncryptDecryptStandard; CONST ULONG m_ulDelta; ULONG m_uKey[SIZE_OF_KEY]; vector
