15,169,392 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.

 Does anyone recognized this "decryption" algorithm? Gary Wheeler23-Nov-21 10:55 Gary Wheeler 23-Nov-21 10:55
 Re: Does anyone recognized this "decryption" algorithm? PIEBALDconsult23-Nov-21 11:10 PIEBALDconsult 23-Nov-21 11:10
 Re: Does anyone recognized this "decryption" algorithm? Peter_in_278023-Nov-21 13:58 Peter_in_2780 23-Nov-21 13:58
 Re: Does anyone recognized this "decryption" algorithm? Gary R. Wheeler23-Nov-21 14:50 Gary R. Wheeler 23-Nov-21 14:50
 Re: Does anyone recognized this "decryption" algorithm? den2k8823-Nov-21 21:49 den2k88 23-Nov-21 21:49
 Re: Does anyone recognized this "decryption" algorithm? PIEBALDconsult24-Nov-21 2:53 PIEBALDconsult 24-Nov-21 2:53
 Re: Does anyone recognized this "decryption" algorithm? Eddy Vluggen26-Nov-21 11:26 Eddy Vluggen 26-Nov-21 11:26
 Re: Does anyone recognized this "decryption" algorithm? Philippe Verdy26-Nov-21 4:32 Philippe Verdy 26-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.
 Re: Does anyone recognized this "decryption" algorithm? harold aptroot26-Nov-21 6:08 harold aptroot 26-Nov-21 6:08
 Re: Does anyone recognized this "decryption" algorithm? PIEBALDconsult26-Nov-21 11:00 PIEBALDconsult 26-Nov-21 11:00
 Re: Does anyone recognized this "decryption" algorithm? harold aptroot26-Nov-21 11:27 harold aptroot 26-Nov-21 11:27
 Re: Does anyone recognized this "decryption" algorithm? brian012528-Nov-21 17:53 brian0125 28-Nov-21 17:53
 Re: Does anyone recognized this "decryption" algorithm? brian012528-Nov-21 17:54 brian0125 28-Nov-21 17:54
 Re: Does anyone recognized this "decryption" algorithm? brian012528-Nov-21 17:31 brian0125 28-Nov-21 17:31
 RA8875 has ridiculous registers honey the codewitch16-Nov-21 2:31 honey the codewitch 16-Nov-21 2:31
 Re: RA8875 has ridiculous registers Greg Utas16-Nov-21 2:39 Greg Utas 16-Nov-21 2:39
 Re: RA8875 has ridiculous registers honey the codewitch16-Nov-21 2:42 honey the codewitch 16-Nov-21 2:42
 Re: RA8875 has ridiculous registers Jörgen Andersson23-Nov-21 4:00 Jörgen Andersson 23-Nov-21 4:00
 Re: RA8875 has ridiculous registers den2k8816-Nov-21 2:45 den2k88 16-Nov-21 2:45
 Re: RA8875 has ridiculous registers honey the codewitch16-Nov-21 5:13 honey the codewitch 16-Nov-21 5:13
 Re: RA8875 has ridiculous registers PIEBALDconsult16-Nov-21 5:10 PIEBALDconsult 16-Nov-21 5:10
 Re: RA8875 has ridiculous registers honey the codewitch16-Nov-21 5:13 honey the codewitch 16-Nov-21 5:13
 Re: RA8875 has ridiculous registers Fueled By Decaff16-Nov-21 5:18 Fueled By Decaff 16-Nov-21 5:18
 Re: RA8875 has ridiculous registers honey the codewitch16-Nov-21 5:19 honey the codewitch 16-Nov-21 5:19
 Re: RA8875 has ridiculous registers Fueled By Decaff16-Nov-21 5:48 Fueled By Decaff 16-Nov-21 5:48
 Last Visit: 31-Dec-99 19:00     Last Update: 18-Jan-22 19:52 Refresh ᐊ Prev1234567891011 Next ᐅ