Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Acrobat Reader File Edit View Window Help ??73% , Sat 9:21 PM a E ?p5.pdf Home T

ID: 3713176 • Letter: A

Question

Acrobat Reader File Edit View Window Help ??73% , Sat 9:21 PM a E ?p5.pdf Home Tools p5.pdf Sign In 7596 General Reference: en. Caesar History Caesar used this for his personal corespondence, but it is also a classic cereal box toy for kids. Basic Idea The letters in the alphabet can be "shifted" some umber over For example, with a shift of 1, ab,bcc-d etc, while with a shift of 2 a-c b-dc-e, etc Computers store letters as mmbers, so you can easily "shiff" a letter over to a new symbol by converting the letter to a umber, adding some amount, and changing it back again For example, in ASCII (one of many a number letter mapping for computers). the lower case letter 'a is 97, "b' is 98, etc. In python, the function to get a umber from a letter is called ord) and the function to get a letter from a mumber is called chr(). Below is an example console nun: orda) >chr(97) >> chr(ord'3) 97 Traditionally Caesar shifts wrap around" from z to a (so shifting 2 for "Z results in b").However, with a computer we can allow a little more range, so we'll wrap around if the number is less than 32 (a space) or more than 126 (a). This means that with a shift of 1, an becomes a space, and with a shift of -1 a space becomes a - Note: Wewill alwars cncode a newlinc character as a newline character for Functions get caesar mapping(shift, message) This fiunction accepts a shift amount (positive or negative) and a message and retuns the smallest encoding dictionary needed to encode the message. Remember to wrap as outlined above (you may assume that the shift is in the range of [-94,94]sothat you never have to wrap twice). caesar encode(shift, message: This function accepts a shift amount (positive or negative) and a message and retums the encoded message. Hint: You already know how to do a substirution encoding if yoiu had an encoding dictionary for this shift amount... caesar decode (shift, essage) This function accepts a shift amount (positive or negative) and an encoded nuch to shift it back message and returns the decoded message Note: shift is how much the message was shified, not how 21

Explanation / Answer

def get_caesar_mapping(shift, message):
ret_dict = {}
for c in message:
if c == ' ':
ret_dict[c] = c
else:
newOrd = ord(c) + shift
m = chr(newOrd)
if newORd < 32:
diff = 32 - newOrd
m = chr(126-diff)
elif newOrd > 126:
diff = newOrd - 126
m = chr(32+diff)
ret_dict[c] = m
return ret_dict

# copy pastable code link: https://paste.ee/p/z76n6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote