I have to write a program that will decode a Ceasar cypher with any possible rotation length on a long string that will be imported into the program. I'm trying to figure out some pseudo coding on how I want to tackle this problem but there is one key thing that I cannot figure out.
I have no clue how to go about writing a function that will find the largest occurrence of a letter in a string, and use that percentage of occurrence to find the amount shifted from a standard percentage of letter usage in the English language.
Essentially what I want to do is find the most used letter in the string, then find the difference between the encoded string max used letter and a constant given, to find my rotation key. Then use that key to decode the string.
Any help with ideas of possible ways to create a function that will count the occurrence of letters in a string will be big step forward as I go on writing the rest of my program.
I have but most methods use a dictionary or complicated method which I haven't learned yet still being new to python. So I was hoping to talk about other methods to do it instead of having someone point me to something that I obviously would already have done. But thanks for the help anyway
>>> import string
>>> s = 'I have to write a program that will decode a Ceasar cypher with any possible rotation length'
>>> dd = dict(zip(string.ascii_lowercase, [s.count(c) for c in string.ascii_lowercase]))
I can get a function to find the largest number of times any letter is used, but what I don't know is how to let python use the actual letter itself that is used the most. Such as if 'T' happens to be used the most then use the ascii value of ord(T) for the rest of my program instead of simply finding an int value telling me the most times anything is used.