USING PYTHON:
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and returns a string as output.
The cencrypt() function you write in lab today needs to work on strings that contain upper-case letters, lower-case letters, or both. The output string should be all upper-case letters. (The Romans of Caesar's time used only what today we call upper-case letters.)
So a call to cencrypt("Caesar", 1) should return (return not print) the string “DBFTBS” and a call to cencrypt(“DBFTBS”, -1)should return the string "CAESAR".
The string function .upper() mentioned in the assigned reading in Chapter 7.3 of Zybooks that gives back a version of its string that has all alphabet characters converted to upper case may be useful here.
You may not use either of the Python functions ord() or chr() for this lab.
def cencrypt(plainText, shift): cipherText = "" alphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for ch in plainText.upper(): x = alphas.find(ch)+shift x = x % 26 cipherText += alphas[x] return cipherText # Testing res1 = cencrypt("Caesar", 1) print(res1) res2 = cencrypt(res1,-1) print(res2)
Get Answers For Free
Most questions answered within 1 hours.