Hash collision checkin
I wanted to do some fun testing with SHA256 and ya how do i do collision checkin? 😛
29 Replies
You can use a
HashSet<T>
or a Dictionary<TKey, TValue>
. Add the created hash to these collections and when creating a new hash, check if said collections already contain ita collision just means 2 inputs produced the same hash
so to check for them, check for duplicate hashes over your inputs
You will never see a hash collision with SHA256 so this is kind of an irrelevant question.
well that's not true
every hash will have a collision at some point
just for now there are no known ones for sha256
I mean in practice.
He was trying to find one.
It's not going to happen for him.
well what about j4f
ikr
i just dont know how im gonna do it
more than a while true and feed random stuff in
i tried to do so, it ate my RAM very quickly
so im just looking for suggestion from people, one might have better approach than me
what is your end goal?
see if any collision appear, by accident
but why
i dont actually know
it's more likely that an asteroid will hit earth and kill you in the next second than you finding a sha256 collision
every hash will have a collision at some pointwanna find my luck
i think there are more productive things to do
as you've already found, you don't have the resources to do this in a meaningful way
does it have to really be meaningful?
if you don't want to waste your time, yeah
i have too much time to waste
just wanna invest some into a j4f project
i mean if it's fun watching nothing happen and spiking your power bill go for it
not sure what you need our help for
i want an efficient way more than while true and fill a hashset with results
then try to find one
im finding one while waiting for an answer here
i want different answers so i can learn something
consider how many computers are mining bitcoin, which basically depends on the uniqueness of sha256 hashes
all that compute hasn't found a hash collision yet
so you know im doing it for no real purpose
i dont have a purpose
im just doing it for fun
but my point is, even for fun you can't do it
you don't have the memory to store all the inputs and hashes you're creating
i know i cant but why dont just try it?
i can't stop you, i can only tell you there's no point
if it's fun for you it's fun for you
i absolutely know that there's absolutely no point
well nobody will have better suggestions
good luck i guess
Ignoring pesky things like OOMs and random solar flares flipping bits of your computer's memory, this is guaranteed to find a collision.
It's an implementation of Denis's idea at the top of the thread.
We'll ignore for now that Dictionary can't hold
2^256
elements, since you'll OOM well ahead of that point. 😉
You'll see that I put an upper bound on this loop. Since each iteration of the loop increments i, we can hopefully all agree that this program will eventually terminate. Ignoring things like OOMs, solar flares, dictionary limitations, etc., here's a question left to the reader: is this program guaranteed to hit the Console.WriteLine
block before it terminates, or might it terminate without writing anything to the console (by simply exhausting the loop condition)?It should be guaranteed to print a collision before the loop terminates, no?