Simple bitcoin mining algorithm I'm trying to figure out how does simple Bitcoin mining algorithm works in plain simple c or c#  or some pseudo language. I've found an example at http://pastebin.com/EXDsRbYH, but unfortunately It isn't clear what it does. I was unable to run it.

Suppose I have only one input: a Bitcoin wallet "abc..." which I would like to be used for the Bitcoins to be mined. I need simple to understand algorithm that will do the bitcoin mining on one machine with one thread on one cpu [I know it will take ages to complete :)]
The simplest miner would work like this:


Request a new Getwork from a given pool/bitcoind with specified credentials
For nonce=0;nonce&lt;0xFFFFFFFF;nonce++

Set Getwork Data nonce
SHA-256 hash the Getwork Data (block header)
Check if hash result is smaller than Getwork Target, if so, submit a share
If more than 1 second passed since you received Getwork, stop the loop

GOTO: 1


Now, if you want something that could rise up to par with currently used miners, you need to consider:


OpenCL calculations, without this you will never get the high hashrates of graphic cards.
Midstate, or in other words hashing optimization. First half of Getwork Data doesn't change, so no point in calculating midstate for each hash.
Longpolling, makes you calculate less stale blocks.
Rollntime, minimizes communication with the pool.