Re: Reverse biwise operation and xor?



In article <dd38f620-5d5d-482b-8f35-d75b28036f7e@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Mrki [MCAD] <zeljko.markic@xxxxxxxxx> 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
.



Relevant Pages

  • Re: True = -1 ?
    ... > I can't for the life of me understand why he continues to call VB's AND, OR, ... If VB supported logical AND, OR, XOR, etc. operators, then it ... Individual gates typically act on individual bits.... ... VB's logical operations yield numerical results based on bitwise comparisons. ...
    (microsoft.public.vb.general.discussion)
  • Re: puzzle
    ... this remains a stunning irrevelance to the fact that the XOR ... Even if the bitwise representation is not accessible any ... The algorithm will still be O. ... Then all of our XOR solutions will fail and he will ...
    (comp.programming)
  • bitwise decimal operators
    ... bitwise operators when applied to base-10 numbers. ... abstract operators AND, OR, and XOR. ... the larger digit of each pair. ... Wherever there's a 0 in the ditmask, ...
    (comp.lang.c)
  • Re: Usisng logical operators with integers in VB
    ... As well there's the Xor and Not operators. ... But as to a greater than operator that is bitwise, I actually have never heard of such a thing. ... any duplicate options set. ... Dim i As Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: puzzle
    ... Most modern languages do support bitwise operations on integers. ... Perl has bitwise xor. ...
    (comp.programming)