Question

Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers...

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'

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

def backwards_cipher(plaintext, key):
listSubString=[]
while len(plaintext)>key:
subStr=plaintext[0:key]
plaintext=plaintext[key:]
listSubString.append(subStr)
listSubString.append(plaintext)
cipherText=""
for strings in listSubString:
cipherText+=strings[::-1]
return cipherText

print("Plain text: alexanderhamilton\nCipher Text:",backwards_cipher("alexanderhamilton",4))
print("\nPlain text: dogsarecool\nCipher Text:",backwards_cipher("dogsarecool",3))
print("\nPlain text: lastweekisawafilm\nCipher Text:",backwards_cipher("lastweekisawafilm", 5))

output

code

def fence_cipher(plaintext):
firstList=[]
secondList=[]
i=0
for ch in plaintext:
if(i%2==0):
firstList.append(ch)
else:
secondList.append(ch)
i+=1
cipherText=""
for ch in firstList:
cipherText+=ch
for ch in secondList:
cipherText+=ch
return cipherText

print("Plain text: vivalavieboheme\nCipher Text:",fence_cipher("vivalavieboheme"))
print("\nPlain text: meetmeinthecoverofdarkness\nCipher Text:",fence_cipher("meetmeinthecoverofdarkness"))
print("\nPlain text: ichbineinberliner\nCipher Text:",fence_cipher("ichbineinberliner"))

output

code

def column_cipher(plaintext):
key=5
   # Each string in ciphertext represents a column in the grid.
ciphertext = [''] * key
   # Loop through each column in ciphertext.
for col in range(key):
pointer = col
# Keep looping until pointer goes past the length of the message.
while pointer < len(plaintext):
           # Place the character at pointer in message at the end of the
           # current column in the ciphertext list.
ciphertext[col] += plaintext[pointer]
           # move pointer over
pointer += key
   # Convert the ciphertext list into a single string value and return it.
return ''.join(ciphertext)

print("Plain text: thequickbrownfoxjumped\nCipher Text:",column_cipher("thequickbrownfoxjumped"))
print("\nPlain text: gotosecretspotatfive\nCipher Text:",column_cipher("gotosecretspotatfive"))
print("\nPlain text: areyouhungry\nCipher Text:",column_cipher("areyouhungry"))

output

code snapsIf you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python code. NO importing modules. you may not use: contains(), index(), sum(),join(), split(). def column_cipher(plaintext): •...

    Python code. NO importing modules. you may not use: contains(), index(), sum(),join(), split(). 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: o The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" o All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. • How it works: o First, transpose the text into 5 different columns by writing...

  • Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple...

    Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext. Example Key (Shift): 3 Plaintext: Abc Ciphertext: Def Task Your goal is to implement a Caesar cipher program that receives the key and an encrypted paragraph (with uppercase and lowercase letters, punctuations, and...

  • using the website repl.it (must be done in Javascript) PGM #1 Write a Java program that can perform the Caesar cipher fo...

    using the website repl.it (must be done in Javascript) PGM #1 Write a Java program that can perform the Caesar cipher for English messages that include both upper and lowercase alphabetic characters. The Caesar cipher replaces each plaintext letter with a different one, by a fixed number of places down the alphabet. The cipher illustrated here uses a left shift of three, so that (for example) each occurrence of E in the plaintext becomes B in the ciphertext. For example...

  • WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...

    WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...

  • Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could...

    Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could you possibly make it as simple as you can without losing functionality. please include comments, that would help me better understand Example of PlayFair Cipher: https://en.wikipedia.org/wiki/Playfair_cipher The Playfair cipher uses a 5 by 5 table containing a key word or phrase. Memorization of the keyword and 4 simple rules was all that was required to create the 5 by 5 table and use the...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • 3) Out of the following, name which kind of attack you carried out in part 1...

    3) Out of the following, name which kind of attack you carried out in part 1 and part2: a. ciphertext only, b. known plaintext, c. chosen plaintext, d. chosen ciphertext. Explain your answer Problem 3 10 points] A 4-bit long message was encrypted using one-time pad to yield a cipher-text “1010” Assuming the message space consists of all 4-bit long messages, what is the probability that the corresponding plaintext was “1001”? Explain your answer. Problem 4 Assume we perform a...

  • Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user...

    Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user to specify the key and the text to be encrypted. A Caesar cipher is a simple substitution cipher wherein each letter in the message is shifted a certain number of spaces down the alphabet -- this number is called the key. a b c d e f g h i j k l m n o p q r s t u v w...

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the...

    JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the input message so that it’s easier to work with. Write a method called normalizeText which does the following: Removes all the spaces from your text Remove any punctuation (. , : ; ’ ” ! ? ( ) ) Turn all lower-case letters into upper-case letters Return the result. The call normalizeText(“This is some \“really\” great. (Text)!?”) should return “THISISSOMEREALLYGREATTEXT” Part 2 - Obfuscation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT