Skip to content

Commit

Permalink
Improve CRC performance (#412)
Browse files Browse the repository at this point in the history
* Find correct parameters for crc and datarange

* Adapt output to URH values

* Added bit2int method and a length fix

* Cython implementation of crc

* cython implementation for crc (first shot)

* Fixed cython crc algorithm and renamed old crc algorithm to reference_crc.
Added tests that compare results of old and new algorithm.

* Huge performance increase for crc bruteforce test

* Performance test with cython code within python

* Cleaned up

* - Removed padding of data to %8 bits
- Some bugfixes

* performance improvement for guess_standard_parameters_and_datarange

* minor updates

* Delta Improvement

* slight performance improvement of delta algorithm

* Delta improvement implemented and used by default

* Delta improvement implemented and used by default

* Delta improvement implemented and used by default

* Bugfix for homematic encoding/decoding
  • Loading branch information
jopohl authored Mar 20, 2018
1 parent 9869c7a commit cdc10d7
Show file tree
Hide file tree
Showing 10 changed files with 20,767 additions and 16,792 deletions.
1 change: 1 addition & 0 deletions .pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file modified data/decodings/homematic
Binary file not shown.
8 changes: 4 additions & 4 deletions data/decodings/homematic.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ int main(int argc, char **argv)
dec[offset+0] = enc[offset+0];

dec[offset+1] = (~enc[offset+1])^0x89;
for(i = offset+2; i < max; i++)
for(i = offset + 2; i < max - 3; i++)
dec[i] = (enc[i-1]+0xdc) ^ enc[i];
dec[offset+i] = enc[offset+i] ^ dec[offset+2];
dec[i] = enc[i] ^ dec[offset+2];

dec[max-1]=0; // Set CRC to 0x0000
dec[max-2]=0;
Expand Down Expand Up @@ -85,9 +85,9 @@ int main(int argc, char **argv)
enc[offset+0] = dec[offset+0];

enc[offset+1] = ~(dec[offset+1]^0x89);
for(i = offset+2; i < max; i++)
for(i = offset + 2; i < max - 3; i++)
enc[i] = (enc[i-1]+0xdc) ^ dec[i];
enc[offset+i] = dec[offset+i] ^ dec[offset+2];
enc[i] = dec[i] ^ dec[offset+2];

enc[max-1]=0; // Set CRC to 0x0000
enc[max-2]=0;
Expand Down
Binary file modified data/decodings/homematic_complete
Binary file not shown.
18 changes: 8 additions & 10 deletions data/decodings/homematic_complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ int main(int argc, char **argv)
*/

// Decrypt
dec[offset+0] = enc[offset+0];

dec[offset+1] = (~enc[offset+1])^0x89;
for(i = offset+2; i < max; i++)
dec[offset+0] = enc[offset+0];
dec[offset+1] = (~enc[offset+1])^0x89;
for(i = offset + 2; i < max - 3; i++)
dec[i] = (enc[i-1]+0xdc) ^ enc[i];
dec[offset+i] = enc[offset+i] ^ dec[offset+2];
dec[i] = enc[i] ^ dec[offset+2];

// Recompute CRC and overwrite with FAKE-CRC, if CRC was OK before
if(crc_ok)
Expand Down Expand Up @@ -190,12 +189,11 @@ int main(int argc, char **argv)
*/

// Encrypt
enc[offset+0] = dec[offset+0];

enc[offset+1] = ~(dec[offset+1]^0x89);
for(i = offset+2; i < max; i++)
enc[offset+0] = dec[offset+0];
enc[offset+1] = ~(dec[offset+1])^0x89;
for(i = offset + 2; i < max - 3; i++)
enc[i] = (enc[i-1]+0xdc) ^ dec[i];
enc[offset+i] = dec[offset+i] ^ dec[offset+2];
enc[i] = dec[i] ^ dec[offset+2];

// Overwrite with correct CRC
crcvalue = crc(&enc[8], max-2-8);
Expand Down
Loading

0 comments on commit cdc10d7

Please sign in to comment.