Decoder programEncoded with caesar cipher, need make generic decoder
Page 1 of 1
12 Replies - 2738 Views - Last Post: 28 February 2010 - 12:41 PM
#1
Decoder program
Posted 26 February 2010 - 04:03 PM
Ok so what I am trying to do for a homework is make a generic decoder on any encrypted text ( file.txt) that have been encrypted with caesar cipher. We found that 'E' was the most frequently used letter in a given example text. In this case for my homework, my teacher gave me the preamble to the constitution encrypted. And I have to somehow find the most reoccurring letter in the encrypted text. Then use that letter to find the shift amount. From there the program has to decode based on the shift amount.
My problem right now is finding out how to get the most frequently used letter.
I was thinking of putting the txt through a loop, but I have absolutely no Idea what to do next..
Maybe sort then find w/e "string" is largest or most occurred.. I dunno, im really stumped. Can anyone point me in the right direction?
Replies To: Decoder program
#2
Re: Decoder program
Posted 26 February 2010 - 04:18 PM
#3
Re: Decoder program
Posted 26 February 2010 - 04:24 PM
http://docs.python.o...y/stdtypes.html
You gotta show me some code before I show you code.
This post has been edited by atraub: 26 February 2010 - 04:25 PM
#4
Re: Decoder program
Posted 26 February 2010 - 05:13 PM
In regards to my situation the code is python
And I will get right on working on some codes, ill send something in soon
#5
Re: Decoder program
Posted 26 February 2010 - 05:57 PM
stuff = "i like pie"
letters = {}
for c in stuff:
if not letters.has_key(c):
letters[c] = 1
else:
letters[c] += 1
print letters['i'] # should print 3
print letters['e'] # should print 2
Should get you started.
#6
Re: Decoder program
Posted 27 February 2010 - 02:20 PM
What I am trying to do is use redirection and use any given textfile to be put into my decoder program.
My problem is I don't know how to make the file input into a variable in my program.
python hw3.py < code.txt
I have something like filename = raw_input()
print filename
to test, but I get a EOFError
#7
Re: Decoder program
Posted 27 February 2010 - 02:52 PM
This post has been edited by cnampheonix: 27 February 2010 - 03:04 PM
#8
Re: Decoder program
Posted 27 February 2010 - 03:26 PM
I know the most reoccurring letter is 'e' with about a 12.701% frequency
so what I tried to do was get the frequency of each letter and if it was greater than or equal to 11% then it would take that element # and subtract 4 to get the shift amount.
for char in uppers:
if char.count / 100 >= .11:
ROT_AMOUNT = uppers[char] - 4
This post has been edited by cnampheonix: 27 February 2010 - 07:08 PM
#9
Re: Decoder program
Posted 27 February 2010 - 09:49 PM
if char.count / 100.0 >= 0.11:
Instead.
#10
Re: Decoder program
Posted 27 February 2010 - 10:20 PM
I tried putting a return ROT_AMOUNT, but it keeps saying return is outside the function
I tried placing the return ROT_AMOUNT everywhere
-removed for plagiarism concerns
This post has been edited by cnampheonix: 28 February 2010 - 09:39 AM
#11
Re: Decoder program
Posted 28 February 2010 - 09:38 AM
Is there a way to fix this?
Also my code gets cut off the end of the line and writes the rest of the word on the next line. Is there a way to fix it so it won't cut words when they reach the end of the line?
-removed for plagiarism concerns-
This post has been edited by cnampheonix: 28 February 2010 - 12:41 PM
#12
Re: Decoder program
Posted 28 February 2010 - 09:58 AM
outstr = ""
for char in whatever:
outstr += char
print outstr
#13
Re: Decoder program
Posted 28 February 2010 - 12:41 PM
|
|

New Topic/Question
Reply




MultiQuote






|