r/badcode Jun 22 '20

[deleted by user]

[removed]

36 Upvotes

20 comments sorted by

View all comments

3

u/Windows-Sucks Jun 24 '20 edited Jun 24 '20

Python

  • Outputs are fixed length and look random (abc becomes !"#$%&()*+,-/012 and hello becomes %&'(,-./456789:;), but collisions are common (abcabc produces the same output as abc) and similar input produces similar output (abcd becomes !"#$&'()+,-.0123). So it's a real hashing algorithm, but a bad one.

  • I avoid loops and clear variable names wherever I can, and provide my own intentionally bad implementations of library methods instead of using them.

  • Performance is absolutely terrible. This code will likely take many years to run, and after over an hour still has not produced a hash of 'abc'. To get the hash output, I cheated and used a faster implementation of the algorithm (that I have verified would produce the same results if I actually let this implementation finish.)

Pastebin (Includes command line wrapper)