{"id":522,"date":"2022-07-06T00:56:46","date_gmt":"2022-07-06T04:56:46","guid":{"rendered":"https:\/\/jeremystein.com\/journal\/?p=522"},"modified":"2022-07-06T00:56:47","modified_gmt":"2022-07-06T04:56:47","slug":"crypto-quip-helper-in-python","status":"publish","type":"post","link":"https:\/\/jeremystein.com\/journal\/crypto-quip-helper-in-python\/","title":{"rendered":"Crypto Quip Helper in Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I like to do the Crypto Quip.  It&#8217;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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>crypto = \"MS SFFV JD PFRIQ SF WZSPDI JMHHMFXQ FK KZHHDX HDZBDQ M'C NZHH MS Z WIFRXC IZVMXW ZNPMDBDJDXS.\"\r\ncommon = \"EARIOTNSLCUDPMHGBFYWKVXZJQ\"\r\nsubs = {}\r\n\r\ndef dosubs():\r\n    plain = \"\"\r\n    for ch in crypto:\r\n        if ch.isalpha():\r\n            if ch in subs:\r\n                plain += subs&#91;ch]\r\n            else:\r\n                plain += ' '\r\n        else:\r\n            plain += ch\r\n    return plain\r\n\r\ndef count():\r\n    freq = {}\r\n    for ch in crypto:\r\n        if ch.isalpha() and ch not in subs:\r\n            if ch in freq:\r\n                freq&#91;ch] += 1\r\n            else:\r\n                freq&#91;ch] = 1\r\n    cc = sorted(freq,key=freq.get,reverse=True)\r\n    i = 0\r\n    for ch in cc:\r\n        print(freq&#91;ch], end=' ')\r\n        print(ch, end=' ')\r\n        while common&#91;i] in subs.values():\r\n            i+=1\r\n        print(common&#91;i])\r\n        i+=1\r\n\r\ncommand = \"\"\r\nwhile command != '!':\r\n    print(dosubs())\r\n    print(crypto)\r\n    command = input(\":\").upper()    \r\n    if len(command) == 2:\r\n        if command&#91;1] in subs.values():\r\n            print(command&#91;1] + \" already assigned.\")\r\n        else:\r\n            subs&#91;command&#91;0]] = command&#91;1]\r\n    elif command == '?':\r\n        count()\r\n    elif command&#91;0].isalpha():\r\n        subs.pop(command&#91;0], None)\r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I like to do the Crypto Quip. It&#8217;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:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/posts\/522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/comments?post=522"}],"version-history":[{"count":3,"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":527,"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/posts\/522\/revisions\/527"}],"wp:attachment":[{"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jeremystein.com\/journal\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}