def crack(text):
    length = len(text)
best = 100000
bestMatch = ''
for key in range(26):
    cand = cypher(text, key)
quality = 0
for l, c in list({letter: sum(1 for c in cand if c == letter) for letter in 'ETAOI'
    }.items()):
    quality += (c / length - freqs[l]) ** 2
if quality < best:
    best = quality
bestMatch = cand
return bestMatch
print(crack(plain))
Finding words in a non-spaced paragraph?