Skip to content

Conversation

@nickmarden
Copy link
Collaborator

[nick@dfpbbd88g Julia-learns-python] (nick/cypher-map-improvements)$ python3 cyphers.py
Do you want to encrypt or decrypt your message?(e/d) e
What message do you want to send? This is an awesome encrypted string.
How much do you want to shift the letters? 17
Kyzj zj re rnvjfdv vetipgkvu jkizex.
[nick@dfpbbd88g Julia-learns-python] (nick/cypher-map-improvements)$ python3 cyphers.py
Do you want to encrypt or decrypt your message?(e/d) d
What is the message you want to decrypt? Kyzj zj re rnvjfdv vetipgkvu jkizex.
This is an awesome encrypted string.
This decryption may not be correct, would you like to see the list of all possible decryptions?(y/n) y
Kyzj zj re rnvjfdv vetipgkvu jkizex.
Lzak ak sf sowkgew wfujqhlwv kljafy.
Mabl bl tg tpxlhfx xgvkrimxw lmkbgz.
Nbcm cm uh uqymigy yhwlsjnyx mnlcha.
Ocdn dn vi vrznjhz zixmtkozy nomdib.
Pdeo eo wj wsaokia ajynulpaz opnejc.
Qefp fp xk xtbpljb bkzovmqba pqofkd.
Rfgq gq yl yucqmkc clapwnrcb qrpgle.
Sghr hr zm zvdrnld dmbqxosdc rsqhmf.
This is an awesome encrypted string.
Uijt jt bo bxftpnf fodszqufe tusjoh.
Vjku ku cp cyguqog gpetarvgf uvtkpi.
Wklv lv dq dzhvrph hqfubswhg vwulqj.
Xlmw mw er eaiwsqi irgvctxih wxvmrk.
Ymnx nx fs fbjxtrj jshwduyji xywnsl.
Znoy oy gt gckyusk ktixevzkj yzxotm.
Aopz pz hu hdlzvtl lujyfwalk zaypun.
Bpqa qa iv iemawum mvkzgxbml abzqvo.
Cqrb rb jw jfnbxvn nwlahycnm bcarwp.
Drsc sc kx kgocywo oxmbizdon cdbsxq.
Estd td ly lhpdzxp pyncjaepo dectyr.
Ftue ue mz miqeayq qzodkbfqp efduzs.
Guvf vf na njrfbzr rapelcgrq fgevat.
Hvwg wg ob oksgcas sbqfmdhsr ghfwbu.
Iwxh xh pc plthdbt tcrgneits higxcv.
Jxyi yi qd qmuiecu udshofjut ijhydw.

@nickmarden nickmarden force-pushed the nick/cypher-map-improvements branch from dbe83d7 to 77b855e Compare October 31, 2017 03:41
@nickmarden nickmarden force-pushed the nick/cypher-map-improvements branch from 77b855e to a792974 Compare October 31, 2017 03:42
if x == max(freqall):
print(''.join(decrypt))

decrypted_strings = []
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First: generate the "decrypted" list of characters for each of the 26 possible shift values. We will use this later.

best_score = 0
best_score_shift = 0

for shift in range(26):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, for each entry in the list of possible decrypted strings, compute the frequency_score for that string.

Each step along the way, if the frequency score that we are looking at now is better (higher) than any score we have seen so far, then it is the "best" frequency score and we want to record it as such. We need to record it so that we can know whether the next or the next or the next decrypted string is "better" or not.

Also, we keep track of the "shift" value associated with the best score, so that we can actually pluck that decrypted string out of the decrypted_strings list at the end of the exercise. Alternatively we could take your approach like this:

    for x in decrypted_strings:
        if frequency_score(x) == best_score:
            print(''.join(x))

But that seemed clunkier to me than simply recording the list index of the best-scoring string, at the moment when we discover that it is the best-scoring string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants