Reverse biwise operation and xor?

Discussion in 'C Programming' started by Mrki [MCAD], Jan 31, 2008.

  1. Mrki [MCAD]

    Mrki [MCAD] Guest

    I have a rather interesting code with 3 input variables that produce
    result (this is a decoder and written by unknown author).

    I have to get cd variable by konwing cl, fm and result of the
    function...
    is this possible?

    Code:
    #define MAKE_TAG_ID( cl, fm, cd)\
    ((((UL)(cl)) << ((TB -1) * 8)) | (((UL)(fm)) << ((TB -1) * 8)) |
    (MAKE_TAG_ID_CODE (((UL)(cd)))))

    And this is related code:

    #define MAKE_TAG_ID_CODE(cd)\
    ( (cd < 31) ? (MAKE_TAG_ID_CODE1 (cd)):\
    ((cd < 128)? (MAKE_TAG_ID_CODE2 (cd)):\
    ((cd < 16384)? (MAKE_TAG_ID_CODE3 (cd)):\
    (MAKE_TAG_ID_CODE4 (cd)))))


    #define MAKE_TAG_ID_CODE1(cd) (cd << ((TB -1) * 8))


    #define MAKE_TAG_ID_CODE2(cd) ((31 << ((TB -1) * 8)) | (cd << ((TB-2)
    * 8)))


    #define MAKE_TAG_ID_CODE3(cd) ((31 << ((TB -1) * 8))\
    | ((cd & 0x3f80) << 9)\
    | ( 0x0080 << ((TB-2) * 8))\
    | ((cd & 0x007F) << ((TB-3)* 8)))



    #define MAKE_TAG_ID_CODE4(cd) ((31 << ((TB -1) * 8))\
    | ((cd & 0x1fc000) << 2)\
    | ( 0x0080 << ((TB-2) * 8))\
    | ((cd & 0x3f80) << 1)\
    | ( 0x0080 << ((TB-3) * 8))\
    | ((cd & 0x007F) << ((TB-4)*8)))

    Thanx for any help
    Mrki [MCAD], Jan 31, 2008
    #1
    1. Advertising

  2. In article <>,
    Mrki [MCAD] <> wrote:
    >I have a rather interesting code with 3 input variables that produce
    >result (this is a decoder and written by unknown author).


    >I have to get cd variable by konwing cl, fm and result of the
    >function...
    >is this possible?


    Not with that code, no.

    Your Subject heading refers to 'xor', but there are no
    xor operations in the code you show, only bitwise or.

    >Code:
    >#define MAKE_TAG_ID( cl, fm, cd)\
    >((((UL)(cl)) << ((TB -1) * 8)) | (((UL)(fm)) << ((TB -1) * 8)) |
    >(MAKE_TAG_ID_CODE (((UL)(cd)))))


    >And this is related code:


    >#define MAKE_TAG_ID_CODE(cd)\
    >( (cd < 31) ? (MAKE_TAG_ID_CODE1 (cd)):\
    >((cd < 128)? (MAKE_TAG_ID_CODE2 (cd)):\
    >((cd < 16384)? (MAKE_TAG_ID_CODE3 (cd)):\
    >(MAKE_TAG_ID_CODE4 (cd)))))


    >#define MAKE_TAG_ID_CODE1(cd) (cd << ((TB -1) * 8))


    Consider the case of cd < 31. In that case, MAKE_TAG_ID_CODE1
    is used, the result of which will be (cd << ((TB -1) * 8)) .
    That will be inclusive-or'd with (((UL)(cl)) << ((TB -1) * 8))
    and with (((UL)(fm)) << ((TB -1) * 8)) . Notice that
    all three parts are left-shifted by the same amount, so the
    "interesting" part of the value will be cl | fm | cd
    Now in any bit position where cl | fm is 1, you cannot tell
    the difference between cl | fm and cl | fm | cd
    because 1 bitwise or'd with anything else is still 1 .

    Thus, you cannot uniquely calculate cd knowing cl, fm, and
    the result of the function -- not unless you have further information
    to know that the bottom five bits of cl and fm are always 0.
    --
    "I was very young in those days, but I was also rather dim."
    -- Christopher Priest
    Walter Roberson, Jan 31, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dogbite
    Replies:
    4
    Views:
    678
    osmium
    Oct 10, 2003
  2. david ullua
    Replies:
    13
    Views:
    640
  3. Micha³ ¦liwka

    region xor operation

    Micha³ ¦liwka, Oct 20, 2005, in forum: C++
    Replies:
    3
    Views:
    356
    Karl Heinz Buchegger
    Oct 20, 2005
  4. raan
    Replies:
    2
    Views:
    435
  5. Buzz Lightyear
    Replies:
    10
    Views:
    1,099
    Alexander Bartolich
    Aug 12, 2009
Loading...

Share This Page