Question
Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers (the backwards cipher, the Rail Fence cipher, and the
Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers (the "backwards" cipher, the Rail Fence cipher, and the Column Transposition cipher) where the ciphertext is created via an altered presentation of the plaintext. The algorithm for each is detailed in the function descriptions in this section. (13 points) def backwards_cipher(plaintext, key): Parameter(s): plaintext ----- a string; the message to be encrypted key ----- an integer; the number to control this cipher Return value: A string; the ciphertext after applying the backwards cipher algorithm Assumptions: The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. The key will be a positive, non-zero, number. How it works: Break up the plaintext into successive subsequences of length key. Flip them all backwards, and put them back together in the same subsequence order. For example, given the plaintext: "alexanderhamilton" and key of 4: Create the substrings of length 4 (if the last substring had less than 4 characters, that's ok): "alex" "ande" "rham" "ilto" "n" Reverse each of these substrings. "xela" "edna" "mahr" "otli" "n" Put them back together to get the ciphertext: "xelaednamahrotlin" Notes: There are no provided tests for this function, you must test it on your own! It will help tremendously if you try this on paper first before you start coding. Examples:
backwards_cipher("dogsarecool",3) 'godrasocelo'
backwards_cipher("lastweekisawafilm", 5) 'wtsalsikeeifawaml' 7 (15 points) def fence_cipher(plaintext): Parameter(s): plaintext ----- a string; the message to be encrypted Return value: A string; the ciphertext after applying the fence cipher algorithm Assumptions: The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. How it works: You "build a fence" with some number of rails (for this project we will use exactly two rails to make it simpler), and then you write letters on the rails in a zig-zag pattern. Once you've written all of the letters on the fence, read each rail from left to right to build the ciphertext message. For example, given the plaintext: "vivalavieboheme" o Build the 2-rail fence: Write the first letter on the top rail. Write the next letter on the bottom rail. The letter after that is written on the top rail, and so on. Repeat this pattern until you are out of letters, creating the "zig-zag" pattern seen below (spaces added for clarity, they are not required): v . v . l . v . e . o . e . e
. i . a . a . i . b . h . m . o Read each rail from left to right: Rail #0: "vvlveoee" Rail #1: "iaaibhm" Combine those strings to form the cipher text: "vvlveoeeiaaibhm" Notes: This is one of the harder functions budget your time wisely! It will help tremendously if you try this on paper first before you start coding Examples:
fence_cipher("meetmeinthecoverofdarkness") 'memiteoeodrnsetenhcvrfakes'
fence_cipher("ichbineinberliner") 'ihienelnrcbnibrie' 8 (20 points) def column_cipher(plaintext): Parameter(s): plaintext ----- a string; the message to be encrypted Return value: A string; the ciphertext after applying the column cipher algorithm Assumptions: The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. How it works: First, transpose the text into 5 different columns by writing each letter from left to right, moving onto the next line after you exhaust all of the columns on a single line. Then, build the cipher text by combining each column from left to right. For example, with the plaintext: "thequickbrownfoxjumped": o First, transpose the text into 5 different columns (spaces added for clarity, they are not required): t h e q u
i c k b r
o w n f o
x j u m p
e d
Now, read each column one at a time: Column #0: "tioxe" Column #1: "hcwjd" Column #2: "eknu" Column #3: "qbfm" Column #4: "urop" Combine the columns from left to right. Your final cipher text is: "tioxehcwjdeknuqbfmurop" Notes: This is one of the harder functions budget your time wisely! o It will help tremendously if you try this on paper first before you start coding. Examples:
column_cipher("gotosecretspotatfive") 'gestocpftroioetvstae'
column_cipher("areyouhungry") 'aurrhyeuynog'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started