DEV Community

[Comment from a deleted post]
Collapse
 
robconery profile image
Rob Conery • Edited

Hi Pedro - great article! One thing to consider is that prime factorization is not a one-way function as it is simply multiplication which means, by definition, it can also be divided. It's difficult to guess and if the numbers are big enough (as with RSA) it's computationally impossible to do it in a reasonable amount of time. To be fair, prime factorization and RSA have more to do with asymmetric key encryption, not hashing. If I have your public key, I can encrypt something that you can then decrypt with your private key. Hashing is different - there's no way to unwind or decrypt a hash.

A one-way function uses modular math (which I'm sure you know) which some people call "clock math". If I add 32 hours to the current time, the answer might be 0845. There's no way to go backwards on that to figure out what both the start and offset were.

Also - it's more than "quite difficult" to figure out the opposite process, it's literally impossible, thus the term "one-way".

Hashing functions are so much fun to play with but extremely hard to get right. Speed plays a huge part in the algorithm - for things like checksums you want it fast but for passwords you kind of want it slow (say 500ms or something). This has to do with rainbow hacks etc.

Thanks for the article!