alesv wrote:
I'm working on OpenCL version - I want it to run on GPU.
That should make it go quite a bit faster!
A few more optimization ideas:
Keyword 3/Keyword 4 odd even testdata_to_encrypt = encryption_key ^ word_to_be_encrypted + (word_to_generate_index<<16);
ignore the left_shifted bits
data_to_encrypt(simplified) = encryption_key ^ word_to_be_encrypted
looking at the encryption_key loop:
if we are hunting odd data (0xnnnnFFFF) the XOR operation means that one variable must be odd and the other even
if we are hunting even data (0xnnnn0000) the XOR operation means that both variables must be odd or both must be even
it is hard to know if word_to_be_encrypted is odd/even, as it has gone through a lot of manipulation/substitution at this point, so not sure there is a good vector to improve on that. the encryption_key gets generated for each keyword, so there is some room to optimize this:
the encryption_key gets bit-shifted >>3 before calculating data_to_encrypt, so if the upper bit of the lower byte <8 then key is even. otherwise, if the upper bit >=8 the key is even.
this upper key comes from the substitution step in the first loop of key generation:
encryption_key += index_transformation[(index >> (n * 4)) & 0x1F] << (n * 4);
since it is the first itteration of the loop, n = 0, so
encryption_key(simplified) = index_transformation[index & 0x1F];
at this point and 'odd even' test could be ran to see if the key is a candidate after the 1st encryption_key step, instead of having to go through all four
Code:
uint32_t decoded_data = 0xFFFFFFFF;
{previous code here}
for(uint16_t key3 = key3_start; key3<0xFFFF; key3++) {
word_to_generate_index = data_to_encrypt32;
index = word_to_generate_index ^ key3;
index += index << 16;
encryption_key = index_transformation[index & 0x1F];
// odd_even test - this same test can be used when testing 0xFFFF or 0x0000 encoded data and testing the 4th keyword
if(!( (decoded_data%2 ) ^ ((encryption_key>>3)%2)) )
continue;
for (uint8_t n = 1; n < 4; n++) {
encryption_key += index_transformation[(index >> (n * 4)) & 0x1F] << (n * 4);
}
encryption_key = (encryption_key >> 3) + (encryption_key << 13);
word_to_be_encrypted = data_to_encrypt32 >> 16;
data_to_encrypt32 = (encryption_key ^ word_to_be_encrypted) + (word_to_generate_index << 16);
//test trailing bits
if( (data_to_encrypt32 & 0x0000FFFF) != (decoded_data & 0x0000FFFF) )
continue;
{code continues here}
Keyword 2, Key-Pair TestNot sure of the math on this, but with a limited known dataset (0xFFFFFFFF & 0x00000000) there should be multiple keypairs (mostly invalid) generated when testing these. take keyword1=0x92a0 and looping through all of keyword_2:
Quote:
key2 loop: 0
key CONFIRMED: 0x92a0 0x282 0x38c0 0x285b
key2 loop: 4095
key2 loop: 8190
key2 loop: 12285
key2 loop: 16380
key2 loop: 20475
key2 loop: 24570
key2 loop: 28665
key CONFIRMED: 0x92a0 0x7922 0x3cda 0xdba8
key2 loop: 32760
key2 loop: 36855
key CONFIRMED: 0x92a0 0x9922 0x36da 0x3ba8
key2 loop: 40950
key2 loop: 45045
key2 loop: 49140
key2 loop: 53235
key2 loop: 57330
key CONFIRMED: 0x92a0 0xe282 0x32c0 0xc85b
key2 loop: 61425
key2 loop: 65520
key2 loop: 0
only one of those values is valid, but my thought is instead of looping through every possible keyword 2, loop through all keyword 1's but only loop keyword_2 from 0x0000 to 0x3FFF. Use that to collect valid keyword_1 and then fully retest all the keyword_1s for every value of keyword_2.
I'm not sure of the math on this, I would be more confident if the substitution table were more balanced, but it could help streamline the bruteforcing.