Implemented the entire brute forcing function

After lots of confusing for loops, it finally worked. Still need to
review code some later to check for possible improvements.