Create a program that can encrypt or decrypt a message using the Caesar Cipher.
If encrypting a message, the program should:
- take as input:
- the plaintext message to be encrypted
- the shift or offset to be used
- return the encrypted or "ciphertext" message.
If decrypting a message, the program should:
- take as input:
- the ciphertext message to be decrypted
- the shift or offset to be used
- return the decrypted or "plaintext" message.
A cipher is a method of disguising a message by encoding it. The Caesar Cipher is a type of substitution cipher where each letter in a message is 'shifted' a certain number of places down or up the alphabet.
For example:
- with a shift of 1, A would be replaced by B, B would become C, and so on.
- with a shift of 3, D would be replaced by G, E would become H, and so on.
If the shift or offset extends past the end of the alphabet, the letter wraps around to the beginning.
For example:
- if you shift Z by 1, you would get A.
- if you shift Y by 4, you would get C.
For our purposes, we will only be shifting letters. All other characters (numbers, punctuation, spaces, etc.) should remain unchanged. Capital letters should remain capitalized; lowercase letters should remain lowercase.
Thus the message "Buzz Off!" encrypted with a shift of 2 would become "Dwbb Qhh!".
Accept the assignment by following the link from our course website. Accepting the assignment will create for you a fork of this repository. Navigate to your fork and use the "Code" button to open a Codespace.
You'll write the encryption function in encrypt.py and the decryption function
in decrypt.py. Run your code from the command line:
python ./encrypt.pypython ./decrypt.pyRead the HELP I'M STUCK guide.
For this problem set, focus on writing a comprehensive set of tests.
The test_encrypt.py and test_decrypt.py files each contain an example test
and further instructions. Ideally, you'll have a set of tests that, if they all
pass, will give you confidence that your program is working correctly.
Want to be a real pro? Write your tests first, then write the code to make them pass.
To run all the tests, use the command:
pytestYou'll have to get your code from your Codespace back to your
GitHub repository. We'll use a tool called git. Here's how:
- In the terminal,
addthe files you've changed. The command, below, adds all files that that have been modified.
git add .committhe changes you've added (you can change the message). "Committing" a set of changes is like taking a snapshot of all the changes you've made. The message is a summary of the changes to help future-you and others.
git commit -m "Completed the Caesar Cipher problem set"pushyour changes to your GitHub repository. "Pushing" your changes sends the snapshot (the "commit") you created to GitHub, thus sharing it with anyone who has access to your repository.
git push- Navigate to your GitHub repository and confirm that the commit has been added to the commit history and your code reflects the changes you made.
For both the encrypt and decrypt functions:
- You've written tests for a wide variety of typical and edge cases.
- Your tests pass.
You could use different strategies or algorithms to perform the encryption and decryption.
- Implement a different algorithm, which may require using different data structures or control flow.
- Make sure your new implementation can pass the same tests as your original implementation.
- Compare the two. Which is better? Which is more efficient?