Jeremy Stein - Journal

«

Crypto Quip Helper in Python

I like to do the Crypto Quip. It’s frustrating to deal with the mechanics of finding all the matching letters, so I wrote a quick program to track my progress for me:

crypto = "MS SFFV JD PFRIQ SF WZSPDI JMHHMFXQ FK KZHHDX HDZBDQ M'C NZHH MS Z WIFRXC IZVMXW ZNPMDBDJDXS."
common = "EARIOTNSLCUDPMHGBFYWKVXZJQ"
subs = {}

def dosubs():
    plain = ""
    for ch in crypto:
        if ch.isalpha():
            if ch in subs:
                plain += subs[ch]
            else:
                plain += ' '
        else:
            plain += ch
    return plain

def count():
    freq = {}
    for ch in crypto:
        if ch.isalpha() and ch not in subs:
            if ch in freq:
                freq[ch] += 1
            else:
                freq[ch] = 1
    cc = sorted(freq,key=freq.get,reverse=True)
    i = 0
    for ch in cc:
        print(freq[ch], end=' ')
        print(ch, end=' ')
        while common[i] in subs.values():
            i+=1
        print(common[i])
        i+=1

command = ""
while command != '!':
    print(dosubs())
    print(crypto)
    command = input(":").upper()    
    if len(command) == 2:
        if command[1] in subs.values():
            print(command[1] + " already assigned.")
        else:
            subs[command[0]] = command[1]
    elif command == '?':
        count()
    elif command[0].isalpha():
        subs.pop(command[0], None)

July 6, 2022 No Comments.

No Comments

Be the first to comment!

Leave a Reply

Your email address will not be published.

«