0
// Size of the encrypted buffer should be 
void XOREncrypt (unsigned char* buffer, unsigned long length, unsigned char* key)
{
    for (unsigned i = 0; i < length/8; ++i)
        for (unsigned j = 0; j < 8; ++j)
            buffer[i*8 + j] = buffer[i*8 + j]^key[j];
}


// Calculate padding
padding = 8 - (pVpnHdr->m_Length%8);

// Zero initialize padding
memset (((unsigned char*)(pVpnHdr + 1)) + pVpnHdr->m_Length, 0, padding);

// Encrypt packet
XOREncrypt ((unsigned char*)(pVpnHdr + 1), pVpnHdr->m_Length + padding, pVpnHdr->m_Key);

what would the above code be in Delphi?

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Duoas
0

Yoink.

OK, one last one, just for the weird operator concerns:

procedure XOREncrypt( buffer: PByteArray; length: longword; key: PByteArray );
  var
    i, j: cardinal;
  begin
  for i := 0 to (length div 8) -1 do
  for j := 0 to 8 -1 do
    buffer[ (i *8) +j ] := buffer[ (i *8) +j ] xor key[ j ]
  end;
// Calculate padding length
padding := 8 -(pVpnHdr^.m_Length mod 8);

// Zero initialize padding
http://www.daniweb.com/forums/post608298-8.html

// Encrypt packet
bp := pVpnHdr;
inc( bp, sizeof( pVpnHdr ) );
XOREncrypt( bp, pVpnHdr^.m_Length +padding, pVpnHdr^.m_Key );

Enjoy!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.