hi i have to write pyhton code for the program below..i have tried doin it but could not get the desired result so if anyone can help me out i would be very thankful.the question is as below..
A Caesar cipher is a simple substitution cipher based on the idea of shifting
each character in a message a fixed number of positions in the alphabet (the
fixed number is called the key). For example “apple” would become “bqqmf”
with a key of 1, and the initial message could be recovered using a key of -1.
Write a program program which encodes a text file using the Caesar cipher
and output the result to a file of the same name with a “.xxx” appended to it.
Your program will need to prompt the user for the name of the text file
containing the initial message and the key to be used.
You will need to use the chr() function to solve this problem. For example if
you wanted to shift a character (lets call it ch) 2 places you could do so in
Python with chr(ord(ch)+2).
Finally modify your Caesar cipher to use two separate keys. The first key
would shift every odd numbered character and the second key every even numbered character.
Above is the question what i have to do it is only a single question
1 2255 bvdet 2,851
Expert Mod 2GB
fury30,
We are not here to do your homework for you. I can give you some examples that should get you started. - >>> s = "This sentence will be scrambled"
-
>>> key = 3
-
>>> cipher = [ord(c)+key for c in s]
-
>>> print ''.join([chr(i) for i in cipher])
-
Wklv#vhqwhqfh#zloo#eh#vfudpeohg
-
>>> cipher = [ord(c)-key for c in 'Wklv#vhqwhqfh#zloo#eh#vfudpeohg']
-
>>> print ''.join([chr(i) for i in cipher])
-
This sentence will be scrambled
-
>>>
Example using string.maketrans: - s = "This sentence will be scrambled"
-
>>> import string
-
>>> m = string.maketrans('abcdefghijklmnopqrstuvwxyz', 'cdefghijklmnopqrstuvwxyzab')
-
>>> s1 = string.translate(s, m)
-
>>> s1
-
'Tjku ugpvgpeg yknn dg uetcodngf'
-
>>>
Example using a dictionary: - >>> cipher = {"a":"g", "b":"h", "c":"i", "d":"j", "e":"k", "f":"l", "g":"m", "h":"n", \
-
"i":"o", "j":"p", "k":"q", "l":"r", "m":"s", "n":"t", "o":"u", "p":"v", \
-
"q":"w", "r":"x", "s":"y", "t":"z", "u":"a", "v":"b", "w":"c", "x":"d", \
-
"y":"e", "z":"f"}
-
-
>>> s = "This sentence will be scrambled"
-
>>> print ''.join([cipher.get(c, c) for c in s])
-
>>> Tnoy yktzktik corr hk yixgshrkj
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tommo |
last post by:
Hello All,
I am a still learning so be easy on me. I am trying to get
some code to work that is using JS and Perl/CGI, I am using AS Perl
and an Apache Server on XP as the webserver. Can anyone...
|
by: G Patel |
last post by:
I wrote the following program to remove C89 type comments from stdin
and send it to stdout (as per exercise in K&R2) and it works but I was
hoping more experienced programmer would critique the...
|
by: Polaris |
last post by:
Hi Experts:
The program creates Panels and inicilize them. When I run the code below,
the program crashes (at the line commented below). Any help is appriciated.
Thanks in Advance!
Polaris
...
|
by: peterggmss |
last post by:
This is a slot machine game, 2 forms. One is the actual game (frmMachine) and the other is in the background and randomizes the images shown on frmMachine. I need to make frmMachine wait for...
|
by: cj |
last post by:
In a project done in 2003 about a year ago I was told to add the
SocketWrench code below into the Windows Form Designer generated code
area as shown below.
#Region " Windows Form Designer...
|
by: stevewilliams2004 |
last post by:
I was wondering if someone could explain the output I am getting for
the program below. What I expected from the main program output was
"Cat" but instead I see "Mammal". The output is also...
|
by: svgeorge |
last post by:
I want to update several tables using one stored procedure.
How can i do this I mean the syntax.etc. declaration etc.
I know the basic syntax as below
CREATE PROCEDURE <Procedure_Name, sysname,...
|
by: fury30 |
last post by:
this is the program as below and now what i need to do is add the following to it but i am not able to get how to do it
# futval.py
# A program to compute the value of an investment
# ...
|
by: psyvanz |
last post by:
Im a college student, my program is a computerized enrollment system, Im using MS ACCESS database in connecting my VB6 program form. Inside i'd created two tables, named "tbstudentinfo" and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |