How to "score" partially decoded ciphertext? I am attempting to write a basic codebreaking program to break simple ciphers (think caesar cipher &amp; railfence) such as these here https://en.wikipedia.org/wiki/Classical_cipher. 

The program will make semi random attempts at decoding the ciphertext, and I need a way to "score" these attempts on how close they are to fully decoded plaintext.
For example "hello world" would score higher than "Kello woHld" or "aellp wprld" which would both score higher than "KRYYP ZPHYI", thus the program can use a hill-climbing or similar method to converge on decoded text.

I am unsure how to score text, perhaps using a dictionary (+regex?) to check for decoded words, or counting occurences of common letters and common groups of 2,3 &amp; 4 letters, then perhaps comparing to known frequencies.

I am not asking for a finished algorithm, just some pointers of how to score text on its "decodedness" / closeness to plaintext.

Edit: I am working with ciphertext 500 to 1000 characters long, would like the system to work with or without word boundaries preserved.
You are looking for a way to measure the similarity between strings, which is usually refered to as string metric. Now in your case one of the strings is the original plaintext and the other is a (more or less) similar string generated by encrypting and decrypting only partially correct. But actually, it doesn't really matter where the other string comes from, you just need to measure how similar they are.

However, there are many string metrics, and it's possible to adapt them to your specific needs. Here are a few common ones:


Hamming distance: Number of mismatching characters
Levenshtein distance: Number of insert/delete/substitute operations


There are countless other ways to measure the similarity between strings, and it has to be determined what is considered similar and what isn't.