4 ms·
I wanted to incorporate this question with an Arduino lesson plan based around key breaking, basically demonstrating that 10,000 combinations might seem like a
by jazzyjackson 5y ago
I wanted to incorporate this question with an Arduino lesson plan based around key breaking, basically demonstrating that 10,000 combinations might seem like a lot when you're doing it by hand, but a computer can brute force it in no time, so how big does a number have to be before it starts taking serious time for a computer to count to it?
That's when I learned compilers will look at your for loops and just predict the result of incrementing a number a million times and skip to the end condition. Was quite a shock to find out the program I write is not the program that runs. I think I added something simple to the loop, like flipping a bit on a digital output to force the loop to actually run.
- tsimionescu 5y agoThe best way to achieve this without changing the code would be to modify the variable to be `volatile`. That way you tell the compiler that you actually care about it reading/writing it from/to memory every time it is read/written.
- kamray23 5y ago-O0 turns off optimizations on most reasonable C compilers.
- lordnacho 5y agoStick random() in there somewhere for each iteration, print it out? Then the optimizer won't be able to just jump to the end.
- jazzyjackson 5y agoActually yes I think that was what we went with, instead of counting from 0 to MAX_INTEGER we generated random numbers that many times, brute forced integer "keys" just fine.