Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Obfuscated code for Encryption algorithm

Obfuscated code for Encryption algorithm

Scheduled Pinned Locked Moved The Weird and The Wonderful
algorithmssecurity
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BadKarma
    wrote on last edited by
    #1
    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

    K M V 3 Replies Last reply
    0
    • B BadKarma
      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

      K Offline
      K Offline
      Kochise
      wrote on last edited by
      #2

      Ask Kernighan and Ritchie or even Stroustrup why they allowed it ! Don't complain if the compiler don't... Kochise

      In Code we trust !

      1 Reply Last reply
      0
      • B BadKarma
        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

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • B BadKarma
          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

          V Offline
          V Offline
          Vikram A Punathambekar
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups