On Wed, Mar 18, 2009, Carter Browne wrote:

> You need to look at your data to see how the bytes are swapped:
> 3 common patterns:
> 
> 1)   Even odd bytes are swapped
> 2)   The data was treated as 32 bit, one system is little ended and the
> other big ended.
> 3)   The entire buffer is reversed.
> 
> Assume pcBuffer is the char * pointer to your data, uiLen is the
> unsigned length of the data.
> 
> For 1)
>   
>     char acTemp = new char[ uiLen ];
> 
>     _swab(pcBuffer,acTemp,uiLen);
>     memcpy(pcBuffer,acTemp,uiLen);
>     delete acTemp;
> 
> Note: uiLen is assumed to be even
> 
> For 2)
> 
>     char   cTemp;
>     int      i,j;
> 
>     for (i=0;i<uiLen;i+=4)
>        {
>        for (j=0;j<2;j++)
>           {
>           cTemp = pcBuffer[ i+j];
>           pcBuffer[ i+j ] = pcBuffer[ i+3-j ];
>           pcBuffer[ i+3-j] = cTemp;
>           }
> 
> Note:  This code assumes that uiLen is a multiple of 4;
> 
> 
> For 3)
> 
>     char cTemp;
> 
>     for (i=0;i<uiLen/2;i++)
>         {
>         cTemp = pcBuffer[ i];
>        pcBuffer[ i ] = pcBuffer[ i+uiLen-i-1 ];
>        pcBuffer[ i+uiLen-i-1] = cTemp;
>        }
> 

Just to note that its #3 that is required by the OP.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to