Jump to content
  • Advertisement
Sign in to follow this  
fantasyz

Help. Problem on porting some code to C#

This topic is 3912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am currently porting some code from C++ to C# but I found something (the syntax) i have never seen before so I don't know what to do. Below is part of the original source code. The 3 lines I marked is the part that I don't understand. MakeH1, f and DissH1 are actually three functions. Can somebody tell me what these lines mean?
void F8_Encrypt( unsigned char *Plain, unsigned char *Cipher )
{
    HalfWord L, R, NewR ;
    int r ;
    HalfWord MakeH1( unsigned char * );         // <<<<<<
    HalfWord f( HalfWord, QuarterWord );        // <<<<<<
    void DissH1( HalfWord, unsigned char * );   // <<<<<<

    L = MakeH1( Plain ) ;
    R = MakeH1( Plain+4 ) ;
    L ^= K89 ;
    R ^= K1011 ;
    R ^= L ;

    for ( r = 0 ; r < 8 ; ++r )
    {
     NewR = L ^ f( R, K[r] ) ;
     L = R ;
     R = NewR ;
    }

    L ^= R ;
    R ^= K1213 ;
    L ^= K1415 ;

    DissH1( R, Cipher ) ;
    DissH1( L, Cipher + 4 ) ;
}


Body of one of the methods:
/*
 * Disassemble the given halfword into 4 bytes.
 */
static void DissH1( HalfWord H, unsigned char *D )
{
    union {
     HalfWord All ;
     unsigned char Byte[4] ;
    } T ;

    T.All = H ;
    *D++ = T.Byte[0] ;
    *D++ = T.Byte[1] ;
    *D++ = T.Byte[2] ;
    *D   = T.Byte[3] ;
}


[Edited by - fantasyz on January 3, 2008 11:18:33 PM]

Share this post


Link to post
Share on other sites
Advertisement
Not sure about the f function but I can give you a little help with the other two.

MakeH1 will assemble a 4 byte word from the four bytes you provide. DishH1 disassembles the word back into 4 bytes..

theTroll

Share this post


Link to post
Share on other sites
I'm guessing you're confused because the declarations are inside another function. It's just the same as if the functions were declared outside the function body. It simply tells the compiler that those functions exist somewhere else, the same as any other function declaration. There is no executable code generated for these lines.

Share this post


Link to post
Share on other sites
Quote:
Original post by f8k8
I'm guessing you're confused because the declarations are inside another function. It's just the same as if the functions were declared outside the function body. It simply tells the compiler that those functions exist somewhere else, the same as any other function declaration. There is no executable code generated for these lines.


Correct. In C#, they are unnecessary.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!