M
Mike Bartels
Hi there,
I am trying to code a 'cloaking algorithm' that my Polar S720i heart rate
monitor puts on every byte that it sends or receives via infrared.
The logic is, that a payload byte array is sent through this algorithm byte
by byte.
This is the logic: B is the source byte, M the result byte
M = (((B + 0x100 - (1<<6)) & 0xff) & (1<<7)) |
(((B + 0x100 - (1<<5)) & 0xff) & (1<<6)) |
(((B + 0x100 - (1<<4)) & 0xff) & (1<<5)) |
(((B + 0x100 - (1<<3)) & 0xff) & (1<<4)) |
(((B + 0x100 - (1<<2)) & 0xff) & (1<<3)) |
(((B + 0x100 - (1<<1)) & 0xff) & (1<<2)) |
(((B + 0x100 - (1<<0)) & 0xff) & (1<<1)) |
!(B & 1)
So if B is 0x00 the following should happen (and also does on a piece of
paper!)
M = (192 & 128) |
(224 & 64) |
(240 & 32) |
(248 & 16) |
(252 & 8) |
(254 & 4 ) |
(255 & 2 ) |
!(0 & 1) = 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 = 0xff
I have programmed it this way:
resultByte[position] =
(((B + 0x100 - (1<<6)) & 0xff) & (1<<7)) |
(((B + 0x100 - (1<<5)) & 0xff) & (1<<6)) |
(((B + 0x100 - (1<<4)) & 0xff) & (1<<5)) |
(((B + 0x100 - (1<<3)) & 0xff) & (1<<4)) |
(((B + 0x100 - (1<<2)) & 0xff) & (1<<3)) |
(((B + 0x100 - (1<<1)) & 0xff) & (1<<2)) |
(((B + 0x100 - (1<<0)) & 0xff) & (1<<1)) |
!(B & 1);
Jetzt gibt es aber mit dem !(B & 1) in der letzen Zeile probleme. Wenn ich
compilieren will, sagt er mir "Operator '!' cannot be applied to operand of
type 'int'.
Well, of course the last line "! (B & 1);" causes the compiler to act up.
"Operator '!' cannot be applied to operand of type 'int'.
I am not a binary person (never did C++, so forgive me)
In my innocence I interpret "B & 1" as "0x00 & 0x01" (with the example of B
= 0x00). I would expect the result to be 0x00 (right?). 0x00 is 0 (int) and
this should be made a 1 through the not ('!') operator. But really I want a
0x01, so the last '|' operator does not tell me that he can't implicitly
convert 'int' to 'byte'.
I understand that if B is anything else but 0 I have problems anyways... But
WHAT exactly can I do?
Please help!
Kind regards,
Michael Bartels
I am trying to code a 'cloaking algorithm' that my Polar S720i heart rate
monitor puts on every byte that it sends or receives via infrared.
The logic is, that a payload byte array is sent through this algorithm byte
by byte.
This is the logic: B is the source byte, M the result byte
M = (((B + 0x100 - (1<<6)) & 0xff) & (1<<7)) |
(((B + 0x100 - (1<<5)) & 0xff) & (1<<6)) |
(((B + 0x100 - (1<<4)) & 0xff) & (1<<5)) |
(((B + 0x100 - (1<<3)) & 0xff) & (1<<4)) |
(((B + 0x100 - (1<<2)) & 0xff) & (1<<3)) |
(((B + 0x100 - (1<<1)) & 0xff) & (1<<2)) |
(((B + 0x100 - (1<<0)) & 0xff) & (1<<1)) |
!(B & 1)
So if B is 0x00 the following should happen (and also does on a piece of
paper!)
M = (192 & 128) |
(224 & 64) |
(240 & 32) |
(248 & 16) |
(252 & 8) |
(254 & 4 ) |
(255 & 2 ) |
!(0 & 1) = 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 = 0xff
I have programmed it this way:
resultByte[position] =
(((B + 0x100 - (1<<6)) & 0xff) & (1<<7)) |
(((B + 0x100 - (1<<5)) & 0xff) & (1<<6)) |
(((B + 0x100 - (1<<4)) & 0xff) & (1<<5)) |
(((B + 0x100 - (1<<3)) & 0xff) & (1<<4)) |
(((B + 0x100 - (1<<2)) & 0xff) & (1<<3)) |
(((B + 0x100 - (1<<1)) & 0xff) & (1<<2)) |
(((B + 0x100 - (1<<0)) & 0xff) & (1<<1)) |
!(B & 1);
Jetzt gibt es aber mit dem !(B & 1) in der letzen Zeile probleme. Wenn ich
compilieren will, sagt er mir "Operator '!' cannot be applied to operand of
type 'int'.
Well, of course the last line "! (B & 1);" causes the compiler to act up.
"Operator '!' cannot be applied to operand of type 'int'.
I am not a binary person (never did C++, so forgive me)
In my innocence I interpret "B & 1" as "0x00 & 0x01" (with the example of B
= 0x00). I would expect the result to be 0x00 (right?). 0x00 is 0 (int) and
this should be made a 1 through the not ('!') operator. But really I want a
0x01, so the last '|' operator does not tell me that he can't implicitly
convert 'int' to 'byte'.
I understand that if B is anything else but 0 I have problems anyways... But
WHAT exactly can I do?
Please help!
Kind regards,
Michael Bartels