Obfuscated code for Encryption algorithm
-
void CArchiveEnc::EncryptData(DWORD dwOffset, DWORD dwLength) { DWORD dwDataLen = m_lpBufCur - m_lpBufStart; if(dwDataLen == 0 || dwDataLen < dwOffset) return; if(dwLength ==(DWORD)-1) dwLength = dwDataLen - dwOffset; if(dwDataLen < dwOffset + dwLength) return; BYTE byFoo = 0x00; BYTE* pData = m_lpBufStart + dwOffset; while(pData < m_lpBufCur) byFoo = *pData++ ^= byFoo; }
The last line is the killer. :doh: Why write it readable if one can put it on a single line :laugh:
codito ergo sum
-
void CArchiveEnc::EncryptData(DWORD dwOffset, DWORD dwLength) { DWORD dwDataLen = m_lpBufCur - m_lpBufStart; if(dwDataLen == 0 || dwDataLen < dwOffset) return; if(dwLength ==(DWORD)-1) dwLength = dwDataLen - dwOffset; if(dwDataLen < dwOffset + dwLength) return; BYTE byFoo = 0x00; BYTE* pData = m_lpBufStart + dwOffset; while(pData < m_lpBufCur) byFoo = *pData++ ^= byFoo; }
The last line is the killer. :doh: Why write it readable if one can put it on a single line :laugh:
codito ergo sum
-
void CArchiveEnc::EncryptData(DWORD dwOffset, DWORD dwLength) { DWORD dwDataLen = m_lpBufCur - m_lpBufStart; if(dwDataLen == 0 || dwDataLen < dwOffset) return; if(dwLength ==(DWORD)-1) dwLength = dwDataLen - dwOffset; if(dwDataLen < dwOffset + dwLength) return; BYTE byFoo = 0x00; BYTE* pData = m_lpBufStart + dwOffset; while(pData < m_lpBufCur) byFoo = *pData++ ^= byFoo; }
The last line is the killer. :doh: Why write it readable if one can put it on a single line :laugh:
codito ergo sum
XORing a byte by the previous byte isn't a particularly great encryption system. Crackable in moments. Also note that the parameter
dwLength
is basically ignored, after determining whether the requested offset and length is within the buffer. Instead, all the data up to the end of the buffer is 'encrypted'. If forced to rewrite this rather than use a proper encryption algorithm, I would replace the last line with:for( DWORD byte = 0; byte < dwLength; ++byte )
{
pData[byte] ^= byFoo;
byFoo = pData[byte];
}Note I'm using array indexing rather than pointer arithmetic. Converting from one to the other is a simple and fundamental optimization which all C++ compilers will implement.
Stability. What an interesting concept. -- Chris Maunder
-
void CArchiveEnc::EncryptData(DWORD dwOffset, DWORD dwLength) { DWORD dwDataLen = m_lpBufCur - m_lpBufStart; if(dwDataLen == 0 || dwDataLen < dwOffset) return; if(dwLength ==(DWORD)-1) dwLength = dwDataLen - dwOffset; if(dwDataLen < dwOffset + dwLength) return; BYTE byFoo = 0x00; BYTE* pData = m_lpBufStart + dwOffset; while(pData < m_lpBufCur) byFoo = *pData++ ^= byFoo; }
The last line is the killer. :doh: Why write it readable if one can put it on a single line :laugh:
codito ergo sum
BadKarma wrote:
while(pData < m_lpBufCur) byFoo = *pData++ ^= byFoo;
They wanted to encrypt the encryption algorithm? :rolleyes:
Cheers, Vikram.
"But nowadays, it means nothing. Features are never frozen, development keeps happening, bugs never get fixed, and documentation is something you might find on wikipedia." - Marc Clifton on betas.
Join the CP group at NationStates. Password:
byalmightybob