# Classify ciphertext vs. plaintext

I'm attempting a rather simple exercise in machine learning and trying to classify samples of text as either plaintext or ciphertext (encrypted).

Here are two samples:

• Plaintext: This is a sentence in plaintext which any human person can read
• Ciphertext: 5oXbLiEZbMUgOOdYy+q4+rsDaqUngBrrUbpVeuu2ggvP6hHObC4GgTLhq

The specific encryption used doesn't have any special attributes I can use to classify (for example, the ciphertext isn't guaranteed to be significantly longer than plaintext), so the task is all about figuring out what text is indistinguishable from random characters and what text is readable plaintext.

My current heuristic involves counting whitespaces and assuming anything with a whitespace ratio above a certain threshold is plaintext, but I'm trying to find a better robust algorithm.

• What forms of plaintext are you needing to test? I.e. what is the full scope of inputs that your algorithm hopes to classify? Some things will be next to impossible (such as detecting whether a compressed file is also encrypted), but the simple English example you give is very easy. – Neil Slater May 5 '17 at 13:00