Question

Question) Write a decryption function decryp_scytale(ctext, key) in PYTHON that would decrypt any ciphertext produced through...

Question) Write a decryption function decryp_scytale(ctext, key) in PYTHON that would decrypt any ciphertext produced through the scytale cipher scheme using a given key.

Note: the key refers to the diameter of the rod. It represents the number of characters which can be written in the one of the rounds around the rod (think of number of rows in a table). Also, remember that it is assumed that the rod can have an infinite length, i.e. there is no limit on the number of columns.

The function description is as follows:

def decryp_scytale(ctext, key):

# your code here

return ptext

Assume that key is a valid integer in string format. The decryption function should return the supposedly deciphered plaintext. When writing the function, watch for the scenario when the last row has missing characters.There are scenarios when the decryption process will fail. In that scenario, the function should return an empty string.

For reference: the encryption function is as follows:

def encryp_scytale(ptext, key):
r = int(key)
c = int(math.ceil(len(ptext)/key))
cipherMatrix = new_matrix(r,c,"")
counter = 0
for i in range(r):
for j in range(c):
cipherMatrix[i][j] = ptext[counter] if counter < len(ptext) else -1
counter+=1
#convert matrix into string vertically  

ctext = ""
for i in range(c):
for j in range(r):
if cipherMatrix[j][i]!=-1:
ctext+=cipherMatrix[j][i]
return ctext

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

Code for decrypting:

def decryp_scytale(ctext, key):
r = int(key)
c = int(math.ceil(float(len(ctext))/r))
cipherMatrix = new_matrix(r,c,"")
counter = 0
for i in range(c):
for j in range(r):
cipherMatrix[j][i] = ctext[counter] if counter < len(ctext) else -1
counter+=1
ptext = ""
for i in range(r):
for j in range(c):
if cipherMatrix[i][j]!='-1':
ptext+=cipherMatrix[i][j]
return ptext

Output:

Add a comment
Know the answer?
Add Answer to:
Question) Write a decryption function decryp_scytale(ctext, key) in PYTHON that would decrypt any ciphertext produced through...
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
  • LANGUAGE: PYTHON Write a function called: d_polybius(). The function applies the decryption scheme for the polybius...

    LANGUAGE: PYTHON Write a function called: d_polybius(). The function applies the decryption scheme for the polybius cipher scheme above. The start of the function call the get_polybius_square function to get the square as a string. The second scenario when the number of characters is not even, excluding ‘\n’. For instance: “71\n5” is an invalid cipher because there is no way that the last number correspond to a character (we need two numbers). A customized version of Polybius square will be...

  • Decrypting the APCO cipher without the key. Decryption without the key is obviously a much more...

    Decrypting the APCO cipher without the key. Decryption without the key is obviously a much more difficult process. Indeed, the purpose of encryption is to make it as difficult as possible for anyone who does not know the key to read the plain text. We will be using an unsophisticated password cracking technique called a brute force attack. A brute force attack on the APCO cipher works by trying every possible four digit key (from 0000 to 9999) and keeping...

  • Write a Python program which implements the following two classical cryptosystem which we covered n class:...

    Write a Python program which implements the following two classical cryptosystem which we covered n class: a) Affine Cipher b) Vigenere Cipher Your program should consist of at least five functions: a) Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. b) Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string...

  • Please write functions to decrypt both the shift (Caesar) and linear ciphers. Also, answer the questions...

    Please write functions to decrypt both the shift (Caesar) and linear ciphers. Also, answer the questions in Python and show how it typed and ran inside the client. The def is what to start with 1) Write a function called decrypt that accepts three numbers (c, m, and k) and returns the corresponding plaintext (p) value as a number. You can assume the modulus (n) is 256. You will need to compute the multiplicative inverse of m mod 256 to...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two...

    Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two functions: encryption and decryption. 2. Use any key you like. (Don't use deceptive in the slides) 3. choose a sentence or a paragraph you like as the plaintext. I have the code I just need the implementation in a different way // C++ code to implement Vigenere Cipher #include<bits/stdc++.h> using namespace std; // This function generates the key in // a cyclic manner until...

  • Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message...

    Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message The code: #include<stdio.h> #include <stdlib.h> char arr[26][26]; char message[22], key[22], emessage[22], retMessage[22]; int findRow(char); int findColumn(char); int findDecRow(char, int); int main() { int i = 0, j, k, r, c; k = 96; for (i = 0; i<26; i++) { k++; for (j = 0; j<26; j++) { arr[i][j] = k++; if (k == 123) k = 97; } } printf("\nEnter message\n"); fgets(message, 22,...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

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
ADVERTISEMENT