Question

In: Computer Science

write a Java method that decrypts a keyword columnar transposition cipher with a given key

write a Java method that decrypts a keyword columnar transposition cipher with a given key

Solutions

Expert Solution

Keyword Columnar Transposition cipher writes plain text in rows and reads ciphertext in columns one by one.

For decryption of the transposition cipher, the following algorithm is used-

  • Find the column length by dividing the length of the message by key length.
  • Then, write the message in form of columns, then reorder the columns which are done by reforming the key.

For simplicity and inclusive function, we assume all the parameters such as the plainText 2D array, cipherText array, message, and the key are passed as parameters to our decrypt function.

 public int[][] decrypt(int cipherText[][], String message, String key)
{
        int i,j;
        int k=0;
        int rowLength = cipherText.length
        int colLength = cipherText[0].length
        int[][] plainText = new int[rowLength][colLength]

        for(i=0; i<colLength; i++)
        {
                //Find the current column
                int curCol= ((int)key.charAt(i)-48)-1;
                for(j=0; j<rowLength; j++)
                {
                        plainText[j][curCol] = cipherText[j][i];
                }
        }
        return plainText;
}

Explanation -

This function decrypts the encrypted message which is passed by using cipherText array. The outer and inner loop use number of columns and number of rows in the inner loop, as the message has to be written in form of columns.

The plainText is returned in form of a 2D array which can be traversed row-wise, to get the decrypted message. The code for that would be-

String decrypted = "";
for(int i=0;i<rowLength;i++)
    for(int j=0;j<colLength;j++)
        decrypted += plainText[i][j]
System.out.println(decrypted);

Code Screenshot -


Related Solutions

Create a Columnar Transposition Cipher in Python that encrypts/decrypts the word "Crypt".
Create a Columnar Transposition Cipher in Python that encrypts/decrypts the word "Crypt".
If a Vigenere cipher uses the keyword CATS, what is the key used and what is...
If a Vigenere cipher uses the keyword CATS, what is the key used and what is the ciphertext that corresponds to the plaintext CATSCANS
Cryptography: Using columnar cipher, find the plaintext and the key that generated this ciphertext: ykccjosaiawiekhriogrrlrni Keep...
Cryptography: Using columnar cipher, find the plaintext and the key that generated this ciphertext: ykccjosaiawiekhriogrrlrni Keep in mind that only letter j was used for padding. (Show your detailed work)
Based on Rectangle transposition techniques, decrypt the following cipher text “LTHBPEEMOSRAIAESIGCVDENTUUBWEFSONES”. Then use the same key...
Based on Rectangle transposition techniques, decrypt the following cipher text “LTHBPEEMOSRAIAESIGCVDENTUUBWEFSONES”. Then use the same key to encrypt the following plain text “the automorphism group is more difficult”.           there is no given key
Write a Java program to encrypt the following message using the RC4 cipher using key CODES:...
Write a Java program to encrypt the following message using the RC4 cipher using key CODES: Cryptography is a method of protecting information and communications through the use of codes so that only those for whom the information is intended can read and process it. Instead of using stream length 256, we will use length 26. When encrypting, let A = 0 to Z = 25 (hence CODES = [2 14 3 4 18]). Ignore spaces and punctuations and put...
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given...
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given that the Vigenere cipher of part (a) with the same keyword was used to produce the ciphertext: VFPUSVSNBVRCNQW Find the plaintext message.        
Write a Java program that will encode plain text into cipher text and decode cipher text...
Write a Java program that will encode plain text into cipher text and decode cipher text into plain text. Create following methods and add them to your class: • a method named encode(String p, int key) that takes a plain text p and encodes it to a cipher text by adding the key value to each alphabet character of plain text p using the ASCII chart. The method should return the encoded String. For example, if p = "attack at...
Write a method in JAVA, called binarySearch, that returns the index of the key element if...
Write a method in JAVA, called binarySearch, that returns the index of the key element if found in the array, otherwise it will return the value of minus(insertion point +1). In main, use an initializer list create an array of ints called nums holding the following values: 1, 4, 13, 43, -25, 17, 22, -37, 29. Test your binarySearch method on nums with a key value number in it (e.g. 4) and one that is not (e.g. 100). Ex. Given...
Encipher the following emperors’ names using a Shift Cipher with the given key. Pompeii, key =...
Encipher the following emperors’ names using a Shift Cipher with the given key. Pompeii, key = D. ___________ Vespasian, key = P. _________ Caligula, key = H. _________ Nero, key = T. _____________
Use Vigenère Cipher to decrypt the following plaintext with the given key key: deceptivedeceptivedeceptive plaintext: wearediscoveredsaveyourself
Use Vigenère Cipher to decrypt the following plaintext with the given key key: deceptivedeceptivedeceptive plaintext: wearediscoveredsaveyourself
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT