Question

In: Computer Science

write a program for the decryption of 2-rail fence cipher. For example, the input "Cmhmtmrooeoeoorw" should...

write a program for the decryption of 2-rail fence cipher. For example, the input "Cmhmtmrooeoeoorw" should return "Comehometomorrow", and input "topaesw lyr" should return "two players". in python

Solutions

Expert Solution

Python code for decryption of 2-rail fence cipher:

def decrypt2RailFence(cipher):

    rail = [['\n' for i in range(len(cipher))]
                  for j in range(2)]

    dir_down = None
    row, col = 0, 0

    for i in range(len(cipher)):
        if row == 0:
            dir_down = True
        if row == 1:
            dir_down = False

        rail[row][col] = '*'
        col += 1
        
        if dir_down:
            row += 1
        else:
            row -= 1
            
    index = 0
    for i in range(2):
        for j in range(len(cipher)):
            if ((rail[i][j] == '*') and
               (index < len(cipher))): 
                rail[i][j] = cipher[index]
                index += 1

    result = []
    row, col = 0, 0
    for i in range(len(cipher)):
          
        if row == 0:
            dir_down = True
        if row == 1:
            dir_down = False

        if (rail[row][col] != '*'):
            result.append(rail[row][col])
            col += 1

        if dir_down:
            row += 1
        else:
            row -= 1
    return("".join(result))
  
print(decrypt2RailFence("Cmhmtmrooeoeoorw"))
print(decrypt2RailFence("topaesw lyr"))

Sample OutPut:


Related Solutions

please solve the following in python: write a program for the decryption of 2-rail fence cipher....
please solve the following in python: write a program for the decryption of 2-rail fence cipher. For example, the input "Cmhmtmrooeoeoorw" should return "Comehometomorrow", and input "topaesw lyr" should return "two players".
please solve the following in python: write a program for the decryption of 2-rail fence cipher....
please solve the following in python: write a program for the decryption of 2-rail fence cipher. For example, the input "Cmhmtmrooeoeoorw" should return "Comehometomorrow", and input "topaesw lyr" should return "two players".
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of...
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of type str and a parameter of type int. The first parameter is the plaintext message, and the second parameter is the encryption key. The method strictly does the following tasks: a. Reverse the operations performed by the encryption method to obtain the plaintext message. The method’s header is as follows: def casesardecryption(s, key):
In the caeser cipher encryption and decryption program below, what do the two lines if(ch >...
In the caeser cipher encryption and decryption program below, what do the two lines if(ch > 'z'){ ch = ch - 'z' + 'a' - 1; } if(ch < 'a'){ ch = ch + 'z' - 'a' + 1; } mean??? I understand that it has something to do with ASCII characters and makes sure that if the encryption/decryption character is more than "z", then it would loop back to "a" instead of outputting a charcter like "{" . I...
Write a Python program to implement Vignere Cipher. Take user input to get plain text and...
Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm....
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm. Implement these two algorithms in their own function. Now write a testing function that demonstrates your algorithms work for all interesting cases!
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get...
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get plain text and key. 2.  Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get...
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get plain text and key. 2.  Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
Write a program that encrypts and decrypts the user input. Note – Your input should be...
Write a program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x) given by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT