TITLE: Whitening a random bit sequence
QUESTION [5 upvotes]: Given an (infinite) stream of uncorrelated random bit with a known "reasonable" bias (say 15-85% 1's) I want to whiten it, e.i. produce a shorter stream of bits that has no bias. The restriction is that the output must be usable as a cryptographically secure ransom bit stream.
The proposal is to compress the stream with a Huffman code constructed from a table of theoretic frequencies of bit sequences (say 10 bits at a time). As the number of bits used increases, will this approach ideal performance?
Clearly, the ratio of bits consumed to bits produced will be nearly ideal, but what about the other interesting properties?

Edit1: A while back I looked around a bit on this topic and found some methods but didn't see this approach used and I'm wondering if it has some sort of hidden flaw.
Edit 2: I'm only interested in the performance of this device for uncorrelated input, that is (to make sure I'm using the term correctly) where the bias of any given element is independent of any and all other values. This happens to make the frequency of any given sequence a function only of it's length and sum.
Edit 3: Assume the input is not a bottle neck, that it can generate bits as fast as I need them.

REPLY [3 votes]: If your goal is to create an unbiased truly random stream, this page has an algorithm which produces results much faster than the usual technique (the one mentioned by qwerty1793 in the comments above).
However, if your concern is simply real-world cryptographic security, since random generators like the one you describe usually produce unbiased streams very slowly, you are better off whitening your stream once using the usual method and using that to seed a provably-secure cryptographic PRNG.
In fact, if you are able to produce your truly-random biased bits as quickly as your PRNG, you could even introduce true randomness to the result by XOR'ing the biased stream with the PRNG output.  This works regardless of the stream's bias (due to the fact that random data XOR'ed with non-random data produces random data).