Re: Unix/Windows bit arrangments

From: Arvind Shyamsundar (Arvind.Shyamsundarat_private)
Date: Mon May 07 2001 - 23:40:07 PDT

  • Next message: Matthew S. Hamrick: "Re: Unix/Windows bit arrangments"

    Hi,
    The Intel architecture processors are little endian. Whereas Motorola etc.
    processors are big endian. Your problem is a normal one whenever one
    attempts to connect these 2 architectures (typically using TCP and
    sockets...)
    
    	Value: 0x1234
    	Intel Memory Representation: 0x34 0x12	(little endian)
    	Motorola: 0x12 0x34				(big endian)
    
    Means the MSB (most significnt bytes) are stored at lower memory locations
    in Motorola (big endian) and MSB is in higher memory location (intel)
    
    What you need to do is therefore reverse the order of bytes in each long you
    received... Check out a utility such as Xvi32
    http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm for
    illustrations of the (simple) principles involved.
    
    You can write a simple function which "twiddles" the bytes in the long to
    get the correct representation (pseudocode):
    
    void twiddle(long)
    {
    	typecast the long to a byte*
    	//traverse half the long (2 bytes) - loop of size 2
    	for (offset=0; offset < 2; offset ++)
    	{
    		interchange(byte[offset], byte[3-offset])
    	}
    }
    
    using the code above (duly implemented in the language of your choice)
    should give you the correct representation of your bytes...
    
    Hope this helps,
    
    Arvind Shyamsundar
    Brainbench MVP for Internet Security
    http://www.brainbench.com
    
    -----Original Message-----
    From: Edwards, David (JTD) [mailto:Edwards.David2at_private]
    Sent: Tuesday, May 08, 2001 5:06 AM
    Subject: Re: Unix/Windows bit arrangments
    
    
    Hi,
    
    > -----Original Message-----
    > From: Adam Berent [mailto:adminat_private]
    > Sent: Monday, 7 May 2001 2:30 AM
    > To: SECPROGat_private
    > Subject: Unix/Windows bit arrangments
    >
    > My only problem is the incompatibilty between the executables
    > I compiled under Windows and Unix.  As far as I can tell the
    > order of the encrypted bytes is reversed.  For example in
    > Windows the bytes would be 1234 5678 while in Unix they are
    > 4321 8765.  Eaach of the for bytes are represented by unsigned longs
    
    Hmmm, that doesn't sound quite kosher.  You may be thinking of
    the big/little endian stuff which is architecture (not OS)
    dependent.  Why would an OS swap around two blocks of
    4 bytes
    
    luckgood :-)
    
    > P.S. I wraped the lines at 72 chars, please let me know if its ok now
    
    Errr, sorry no.  Try hitting the enter key when the line gets this long.
    
    ciao
    dave
    ---
    Dave Edwards
    Justice Technology Division
    Ph: +61 8 82265426 || 0408 808355
    mailto: edwards.david2at_private
    Snail : Justice Technology Division
            GPO Box 2048, Adelaide 5001
    ---
    This message contains confidential information and is intended only for the
    individual named. If you are not the named addressee you should not
    disseminate, distribute or copy this e-mail. Please notify the sender
    immediately by e-mail if you have received this e-mail by mistake and delete
    this e-mail from your system. E-mail transmission cannot be guaranteed to be
    secure or error-free as information could be intercepted, corrupted, lost,
    destroyed, arrive late or incomplete, or contain viruses.The sender
    therefore does not accept liability for any errors or omissions in the
    contents of this message which arise as a result of e-mail transmission. If
    verification is required please request a hard-copy version
    



    This archive was generated by hypermail 2b30 : Fri May 11 2001 - 03:06:58 PDT