Sign in to follow this  
fantasyz

Help. Problem on porting some code to C#

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this