// 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?

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.