Where to get a sample code for a simple substitution cipher solver?

I need to build a software to solve a simple substitution ciphertext (we so not know the key). Aside from trying on the exponential number of keys, no other implementation works and frequency analysis fails for sentences with non-typical frequencies.