Click here to Skip to main content
15,885,366 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.

 
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 
I did not say they are "random", jsut that they are "sufficiently randomized" (meaning that it generates a sufficiently "flattened" distribution in the hash space to minimize the number of collisions of keys and the average access time in the hash table). Generally keys used in hash tables are not flattened, and that's where you need a good hashing function that *pseudo*-randomizes the distribution of their bits.

I've seen videos using STUPID hash functions like:

int hash(char*s) {
  hash=0;
  for (i=0, s[i] != '\0', i++) hash = hash*(i+1) + s[i];
  return hash%N;
}

Here of course this is stupid as not all characters in the string have the same weight, some of them are even completely ignored in the result.

If you don't know what is a hash function and what it must respect, your hash table will not optimize anything and in fact lookups in such hash table will be even SLOWER than a full table-scan where you add keys at end of an array.

If you don't know which factor to use for computing hash value, just use 17, and use an hash table size which is a power of 2 (at 2^4, but an hash table size of 32, 64, 128 or 256 is better); if your hash table size is larger, adjust the factor so that it is rougly doubled (keeping it as a prime) when the hash table size is quadrupled (and take into account the bitsize of each individually "fragment" of the hash key that you "feed": most apps will feed basic integers or bytes). And for evaluating the table size needed, consider the number of keys you'll store, and IF collisions will be managed by storing keys in a separate linked link list, or in "successor" free slots inside the table itself (which increase the "fill factor" and the likelyhood of collisions with other hashes): your hash table should be about 33% to 67% filled with keys to avoid wasting space while keeping collisions still infrequent, with average length of collision lists per bucket lower than 1 (this will be true only if you've used a "good enough" hashing function that corerctly flattens the distribution of bits in the generated hash value space).
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 
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
Fueled By Decaff16-Nov-21 4:18
Fueled By Decaff16-Nov-21 4:18 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 4:19
mvahoney the codewitch16-Nov-21 4:19 
GeneralRe: RA8875 has ridiculous registers Pin
Fueled By Decaff16-Nov-21 4:48
Fueled By Decaff16-Nov-21 4:48 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 5:07
mvahoney the codewitch16-Nov-21 5:07 
GeneralRe: RA8875 has ridiculous registers Pin
Peter Adam25-Nov-21 20:51
professionalPeter Adam25-Nov-21 20:51 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch25-Nov-21 22:19
mvahoney the codewitch25-Nov-21 22:19 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 6:30
mvahoney the codewitch16-Nov-21 6:30 
GeneralCode to determine whether the passed in string is a C style comment block - in T-SQL Pin
honey the codewitch8-Nov-21 15:11
mvahoney the codewitch8-Nov-21 15:11 

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.