Click here to Skip to main content
15,175,953 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 10:55
MemberGary Wheeler23-Nov-21 10:55 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
PIEBALDconsult23-Nov-21 11:10
professionalPIEBALDconsult23-Nov-21 11:10 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Peter_in_278023-Nov-21 13:58
professionalPeter_in_278023-Nov-21 13:58 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Gary R. Wheeler23-Nov-21 14:50
MemberGary R. Wheeler23-Nov-21 14:50 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
den2k8823-Nov-21 21:49
professionalden2k8823-Nov-21 21:49 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
PIEBALDconsult24-Nov-21 2:53
professionalPIEBALDconsult24-Nov-21 2:53 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Eddy Vluggen26-Nov-21 11:26
professionalEddy Vluggen26-Nov-21 11:26 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
Philippe Verdy26-Nov-21 4:32
MemberPhilippe Verdy26-Nov-21 4: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 6:08
Memberharold aptroot26-Nov-21 6:08 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
PIEBALDconsult26-Nov-21 11:00
professionalPIEBALDconsult26-Nov-21 11:00 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
harold aptroot26-Nov-21 11:27
Memberharold aptroot26-Nov-21 11:27 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
brian012528-Nov-21 17:53
Memberbrian012528-Nov-21 17:53 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
brian012528-Nov-21 17:54
Memberbrian012528-Nov-21 17:54 
GeneralRe: Does anyone recognized this "decryption" algorithm? Pin
brian012528-Nov-21 17:31
Memberbrian012528-Nov-21 17:31 
GeneralRA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 2:31
mvahoney the codewitch16-Nov-21 2:31 
GeneralRe: RA8875 has ridiculous registers Pin
Greg Utas16-Nov-21 2:39
mveGreg Utas16-Nov-21 2:39 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 2:42
mvahoney the codewitch16-Nov-21 2:42 
GeneralRe: RA8875 has ridiculous registers Pin
Jörgen Andersson23-Nov-21 4:00
professionalJörgen Andersson23-Nov-21 4:00 
GeneralRe: RA8875 has ridiculous registers Pin
den2k8816-Nov-21 2:45
professionalden2k8816-Nov-21 2:45 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 5:13
mvahoney the codewitch16-Nov-21 5:13 
GeneralRe: RA8875 has ridiculous registers Pin
PIEBALDconsult16-Nov-21 5:10
professionalPIEBALDconsult16-Nov-21 5:10 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 5:13
mvahoney the codewitch16-Nov-21 5:13 
GeneralRe: RA8875 has ridiculous registers Pin
Fueled By Decaff16-Nov-21 5:18
MemberFueled By Decaff16-Nov-21 5:18 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 5:19
mvahoney the codewitch16-Nov-21 5:19 
GeneralRe: RA8875 has ridiculous registers Pin
Fueled By Decaff16-Nov-21 5:48
MemberFueled By Decaff16-Nov-21 5:48 

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.