Click here to Skip to main content
15,878,748 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralDoes anyone recognized this "decryption" algorithm? Pin
Gary Wheeler23-Nov-21 9:55
Gary Wheeler23-Nov-21 9:55 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
PIEBALDconsult23-Nov-21 10:10
mvePIEBALDconsult23-Nov-21 10:10 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Peter_in_278023-Nov-21 12:58
professionalPeter_in_278023-Nov-21 12:58 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Gary R. Wheeler23-Nov-21 13:50
Gary R. Wheeler23-Nov-21 13:50 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
den2k8823-Nov-21 20:49
professionalden2k8823-Nov-21 20:49 
GeneralRe: Does anyone recognized this "decryption" algorithm? PinPopular
PIEBALDconsult24-Nov-21 1:53
mvePIEBALDconsult24-Nov-21 1:53 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Eddy Vluggen26-Nov-21 10:26
professionalEddy Vluggen26-Nov-21 10:26 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Philippe Verdy26-Nov-21 3:32
Philippe Verdy26-Nov-21 3:32 
That's a very bad "algorithm". In fact the transform is not even bijective, because the "magic number" used for the multiplication is not a prime number (it is evidently a multiple of 5, even if it has no divisor by 2, which is a very weak but insufficient condition). This code creates some collisions.
Basically, this should just be a weak "hashing function" for use to compute fast hash keys in hash tables, to distribute the hash keys in a pseudo-random order, however it is limited to hashing short strings (hash tables require a small number of bits in the hash value, but here this hash has the same size as the input, which is assumed to be a multiple of 4 bytes, so typically an hash table would only distriobute the first few bytes of the input strings, ignoring completely the end).

It is extremely easy to decrypt by a very basic cryptanalysis (simply based on statistics, because each block of 4 bytes is encrypted separately, independantly of their position in the data stream).
If there's any app using this code, it should be marked as severely attackable (much more than MD5 which is already easily attackable, even when given some salt).

A much better affine transform would use the result of the previous block as an additive salt for the next block of 4 bytes, and the first block should be salted by an initial 32-bit constant. If this is used to compute a hash key, the hash should be the value you get from processing the last block, i.e. the last 4 bytes, and never the first 4 ones.

Beside this, the bitshifting done here is just here to allow processing unaligned block, in a very inefficient way: you don't need masking the "temporary" with 0xFF000000... if you just cast the temporary value to a byte, and the first part is extending a byte to a 32-bit DWORD before left-shifting, meaning that masking the low bits is unnecessary, and making the high bits would be also unnecessary of the left-shifting was not arithmetic but logical using unsigned byte: DWORD is the incorrect type to use because it is signed. May be the compiler will optimize this, but this code is just waste

But you should be aware that this code processes bytes past the end of the data, if the datasize (sizeof encrypted = sizeof decrypted) is not a multiple of 4 bytes: up to 3 trailing bytes have unpredictable contents and trying to access them could cause memory access violation: this is a clear case of BUFFER OVERFLOW.
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
harold aptroot26-Nov-21 5:08
harold aptroot26-Nov-21 5:08 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
PIEBALDconsult26-Nov-21 10:00
mvePIEBALDconsult26-Nov-21 10:00 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
harold aptroot26-Nov-21 10:27
harold aptroot26-Nov-21 10:27 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
brian012528-Nov-21 16:53
brian012528-Nov-21 16:53 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Philippe Verdy8-Sep-22 20:14
Philippe Verdy8-Sep-22 20:14 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
harold aptroot9-Sep-22 1:01
harold aptroot9-Sep-22 1:01 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Philippe Verdy9-Sep-22 1:31
Philippe Verdy9-Sep-22 1:31 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
brian012528-Nov-21 16:54
brian012528-Nov-21 16:54 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Philippe Verdy8-Sep-22 20:37
Philippe Verdy8-Sep-22 20:37 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
brian012528-Nov-21 16:31
brian012528-Nov-21 16:31 
GeneralRA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 1:31
mvahoney the codewitch16-Nov-21 1:31 
GeneralRe: RA8875 has ridiculous registers Pin
Greg Utas16-Nov-21 1:39
professionalGreg Utas16-Nov-21 1:39 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 1:42
mvahoney the codewitch16-Nov-21 1:42 
GeneralRe: RA8875 has ridiculous registers Pin
Jörgen Andersson23-Nov-21 3:00
professionalJörgen Andersson23-Nov-21 3:00 
GeneralRe: RA8875 has ridiculous registers Pin
den2k8816-Nov-21 1:45
professionalden2k8816-Nov-21 1:45 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 4:13
mvahoney the codewitch16-Nov-21 4:13 
GeneralRe: RA8875 has ridiculous registers Pin
PIEBALDconsult16-Nov-21 4:10
mvePIEBALDconsult16-Nov-21 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.