You are on page 1of 4

Name_________________________________ 05.

02 ASCII Code

This assignment has three parts.

Part One: Programming

Write a program to encode and decode a message. Use the following guidelines to write your
program:
1. Think of a secret message you want to encode. Be creative! Maybe a famous quote, a favorite
lyric, or your personal motto.
2. Using the ord() and chr() functions, encode and decode the message.
3. Optional: Ask the user to guess the message before revealing it.
Display the encoded message in binary, or include a twist by adding 2 to the number.
When decoding, remember to reverse the steps.
4. Neatly print the encoded and decoded messages to the screen.
5. Write the pseudocode for this program. Be sure to include any needed input, calculations, and
output.
Insert your pseudocode here:

1. #comments
2. Def main():
3. Assign value to message, message = If life were predictable it would cease to be life, and be
without flavor. -Eleanor Roosevelt"
4. codeMessage = [ ]
5. For loop, codeMessage. append(ord(m))
6. print("The encoded message:")
7. For loop, for c in codeMessage: print(c)
8. Decoded message = ""
9. print("The decoded message:")
10. For loop, for m in code message: decodedMessage = decoded Message + chr(m)
11. print(decoded message)
12. main()
Part Two: Code the program

Use the following guidelines to code your program:

1. To code the program, use the Python IDLE.


2. Using comments, type a heading that includes your name, today’s date, and a short description
of the program.
3. Follow the Python style conventions regarding indentation and the use of white space to
improve readability.
4. Use meaningful variable names.

Example of expected output: The output for your program should resemble the following
screen shot. Your specific results will vary depending on the choices you make and the input
provided.
Insert a copy of your code from IDLE here:

# Sam Hodges
# 3/15/24
# Purpose: Write a program to encode and decode a message.

def main():

message = "If life were predictable it would cease to be life, and be without flavor. -
Eleanor Roosevelt"

codeMessage = []

for m in message:

codeMessage.append(ord(m))

print("The encoded message:")

for c in codeMessage:
print(c)

print("")

print("")

print("")

decodedMessage = ""

print("The decoded message:")

for m in codeMessage:

decodedMessage = decodedMessage + chr(m)

print(decodedMessage)

main()
Part Three: Post Mortem Review
Complete the Post Mortem Review (PMR). Write thoughtful two- to three-
sentence responses to all the questions in the PMR chart.

Review Question Response


What was the purpose of your program? The purpose of my program was to encode and
decode a message. It was also to practice my skills
with ASCII and using ord() and chr() functions.

How could your program be useful in the real My program could be useful in the real life if
world? someone wanted to hide a message to only be
accessible to those with knowledge of ASCII. It
could also serve as a good learning tool to show an
encrypted message, try to figure it out and then
show what the actual message is.
What is a problem you ran into, and how did you I ran into a problem with my for loop decoding the
fix it? encrypted message. This was because for the loop I
was still using the original message instead of the
new coded message. I fixed this by replacing
message with codeMessage in the program for that
loop.
Describe one thing you would do differently the One thing I would do differently next time I write a
next time you write a program. program is see if it was possible to include a time
delay. This would give the user time to see if they
could guess the the decoded message

You might also like