Caesar_Vigenere I

Spring 2019

The questions below are due on Sunday March 31, 2019; 11:59:00 PM.
 
You are not logged in.

If you are a current student, please Log In for full access to the web site.
Note that this link will take you to an external site (https://oidc.mit.edu) to authenticate, and then you will be redirected back to this page.

Back to Exercise 07

1) Getting Started

This exercise will involve implementing a Caesar and Vigenere Cipher infrastructure, which are covered in the readings for this week, and which we'll review more formally after Spring Break. Many of you will have already encountered these two encryption schemes in other environments as well since they are considered "classics"

For these next few exercises, we'd like for our functions to be able to both encrypt and unencrypt/decrypt messages so that we can cycle back and forth as needed:

We want to be able to cycle back and forth between encrypted and unecrypted messages with our functions

2) Encryption

To do this, we'll implement a Vigenere Cipher as discussed in lecture. We will write two functions to accomplish this, which we can eventually use as needed in order to enable secret communication. The two parts are detailed below:

2.1) Caesar Cipher

Implement a Python function caesar_cipher that takes in three arguments:

  1. message: the string of text to be encoded or decoded
  2. shift: the integer "shift" of the Caesar Cipher
  3. encrypt: A boolean value that encrypts when True and decrypts when False

caesar_cipher should return the "processed" message string (either encrypted or decrypted using a Caesar cipher accordingly).

For our "alphabet", we will use an ASCII character subset for our symbol list. Specifically, we'll use ASCII characters between 32 and 126, inclusive.

ASCII Table Subset we'll use for our Cipher

The Python functions ord() and chr() are useful for converting back and forth between ASCII codes and symbols. Documentation for these functions can be found here.

Debug this code locally, not in the submission box. We won't be increasing the number of submissions.

def caesar_cipher(message,shift,encrypt): pass #Your code here

2.2) Vigenere Cipher

Next up, we want to write a Python function called vigenere_cipher that (also) takes in three arguments:

  1. message: The string of text to be encrypted or decrypted
  2. keyword: The string used as a keyword/phrase for implementing the Vigenere cipher.
  3. encrypt: A boolean value that encrypts when True and decrypts when False

The function vigenere_cipher should return the encrypted or decrypted message based on the keyword/phrase and the variable encrypt. Given a character in your Vigenere keyword, you can get the shift by taking the ASCII code minus 32. Therefore, ' ' implies a shift of 0, '!' implies a shift of 1, etc.

You should assume a working version of caesar_cipher exists in the checker below:

def vigenere_cipher(message,keyword,encrypt): pass #Your code here

Back to Exercise 07



This page was last updated on Sunday March 17, 2019 at 10:56:05 AM (revision 82b5b8d0).
 
Course Site powered by CAT-SOOP 14.0.4.dev5.
CAT-SOOP is free/libre software, available under the terms
of the GNU Affero General Public License, version 3.
(Download Source Code)
CSS/stryling from the Outboxcraft library Beauter, licensed under MIT
Copyright 2017