plain = (
    "Z RD NFEUVIZEX ZW KYVIV ZJ R NRP KF LJV R UZTKZFERIP NZKY GPKYFE KF JVRITY WFI RE VEXCZJY NFIU ZE KYZJ FLKGLK FI TRE Z ZDGIFMV DP TFUV KF FECP GIZEK FLK BEFNE VEXCZJY NFIUJ. RGFCFXZVJ ZW KYZJ YRJ SVVE RJBVU SVWFIV, Z JVRITYVU RIFLEU REU TFLCUE'K JVVD KF WZEU KYV IZXYK KYZEX."
    .upper())
freqs = {'E': 12.7, 'T': 9.1, 'A': 8.2, 'O': 7.5, 'I': 7.0}

def cypher(text, key):
    return ''.join(chr((ord(c) - ord('A') + key) % 26 + ord('A')) if 'A' <=
        c <= 'Z' else c for c in text)

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?