Description
                            Markov chains are back, this time with a full poem and slightly more info! Is it still reversible?
Flag format is ictf{The_Title_of_the_Poem_by_X._Y._Lastname} where X and Y are first and middle initials of the author, respectively. If you believe you have the correct poem but are having issues with flag format, please open a support ticket.
                            Attachments
                            https://imaginaryctf.org/f/nrl7z#markov_revenge.py
https://imaginaryctf.org/f/vxS8g#freqs.txt
                            Writeup 
                            
                                Much like the last one, I haven't written too much of a proper solve script. However, there's a few giveaways. First, the author's name has initials, and the author's name is in the markov text. Thus, the initials are two of J, S, and T. Additionally, by expanding the bits of text that have only 1 possible expansion, you can determine a few of the words in the poem.
Specifically:
wdus - the only English word that contains these letters is sawdust and its derivatives
Lazar - Lazarus (although google doesn't immediately show this)
ryar - either dooryard or lumberyard
uzzle - in some of my searches, google autocorrected this to muzzle with enough other clues
And likely others. With all these clues and some google-fu, you can find the poem. (dooryard sawdust poem is enough of a google search to bring up the poem, for example)
Script to find words with unique expansions.
from markov_revenge import freq_dict
from random import random
def pick(pairs):
    num = random()
    for c, prob in pairs:
        num -= prob
        if num < 0:
            return c
def markov_gen(ln=2000, dct=freq_dict):
    ret = '\n\n'
    for i in range(ln):
        if ret[-2:] in dct:
            ret += pick(dct[ret[-2:]])
    return ret
def find_valid_prevs(key, dct=freq_dict):
    ret = [i[0] for i in dct if i[-1] == key[0] and len(dct[i]) == 1 and dct[i][0][0] == key[1]]
    return ret
def find_uniq(key, dct=freq_dict):
    ret = key
    while ret[-2:] in dct and len(dct[ret[-2:]]) == 1:
        ret += dct[ret[-2:]][0][0]
    while len(valid := find_valid_prevs(ret)) == 1:
        ret = valid[0][0] + ret
    return ret
for key in freq_dict:
    if len(freq_dict[key]) == 1:
        print(key, repr(find_uniq(key)))```
                             
                            Flag 
                            
                                ictf{The_Love_Song_of_J._Alfred_Prufrock_by_T._S._Eliot}