I am writing a program that contains python code that will decode an English
message that was encoded using a Caesar cypher with a fixed
rotation length. It makes use of letter frequencies in
the English language to determine the rotation length.The program should also have some comments within your code to explain what confusing-looking code is doing. These comments should be directly above and indented evenly with the code it is explaining.
The output should look like this
linuxserver1.cs.umbc.edu[101] more code.txt
BJ YMJ UJTUQJ TK YMJ ZSNYJI XYFYJX, NS TWIJW YT KTWR F RTWJ UJWKJHY ZSNTS, JXYFGQNXM OZXYNHJ, NSXZWJ ITRJXYNH YWFSVZNQNYD, UWTANIJ KTW YMJ HTRRTS IJKJSXJ, UWTRTYJ YMJ LJSJWFQ BJQKFWJ, FSI XJHZWJ YMJ GQJXXNSLX TK QNGJWYD YT TZWXJQAJX FSI TZW UTXYJWNYD, IT TWIFNS FSI JXYFGQNXM YMNX HTSXYNYZYNTS KTW YMJ ZSNYJI XYFYJX TK FRJWNHF.
linuxserver1.cs.umbc.edu[102] python hw4.py < code.txt
WE THE PEOPLE OF THE UNITED STATES, IN ORDER TO FORM A MORE PERFECT UNION, ESTABLISH JUSTICE, INSURE DOMESTIC TRANQUILITY, PROVIDE FOR THE COMMON DEFENSE, PROMOTE THE GENERAL WELFARE, AND SECURE THE BLESSINGS OF LIBERTY TO OURSELVES AND OUR POSTERITY, DO ORDAIN AND ESTABLISH THIS CONSTITUTION FOR THE UNITED STATES OF AMERICA.
linuxserver1.cs.umbc.edu[103]

Iam just little bit confuse on how to start and i need some help.

Here are the English frequencies for each letter :

a 8.167%
b 1.492%
c 2.782%
d 4.253%
e 12.702%
f 2.228%
g 2.015%
h 6.094%
i 6.966%
j 0.153%
k 0.772%
l 4.025%
m 2.406%
n 6.749%
o 7.507%
p 1.929%
q 0.095%
r 5.987%
s 6.327%
t 9.056%
u 2.758%
v 0.978%
w 2.360%
x 0.150%
y 1.974%
z 0.074%
Hints:

Make use of the fact that 'E' is the most frequently used letter in English.
Notice that the next most-frequent letter, 'T', occurs significantly less often.
The problem is i can do it on java but not python and i just started

Comments
Show effort

You can't just drop off your homework assignment and expect us to do it for you, put some effort in and we'll help you figure out issues.

Sir,i know one way of doing the actual cipher bit would be to have 2 strings to encode/decode:

1
decoded = "abcdefghijklmnopqrstuvwxyz"
2
encoded = "tuvwxyzabcdefghijklmnopqrs"


In this case decoded[0] = a, encoded[0] = t. You can use the same indexes to translate your input.

But as the rotation length needs to be calculated, it might be better to use modular arithmetic (MOD 26) to calculate the values after the alphabet has been shifted but i am having problem putting it on python.

the majority of them seem to be the unicode value -5; I'm not terribly patient with math, Gribboulis is probably your man for this, hope he stops by.

Thank you guys i got it, sorry for the incovenience am used to java

but holdup i have my lab3.py as this

import string

def main():

	#read input <string> from user

	#convert <string> to all uppercase

	#for each <char>acter in <string>
    
		#if <char> is not a space
			
			#convert <char> to its ASCII <value>
		
			#rotate <value> by a given amount
        
			#convert <value> back to a character, <char>
        
			#print out <char>

but they want us to decode the alphabetical letters to look like the alphabets above.i am confuse a bit.do i have to use if and for statements.i know i have to use chr and ord to convert.please i need help

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

The post in my signature tries to give clear advice on posting and using the forum. It would be useful for you to follow the advice.

This article has been dead for over six months. Start a new discussion instead.