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

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
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...
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
in java code In the class Hw2, write a method removeDuplicates that given a sorted array,...
in java code In the class Hw2, write a method removeDuplicates that given a sorted array, (1) removes the duplicates so that each distinct element appears exactly once in the sorted order at beginning of the original array, and (2) returns the number of distinct elements in the array. The following is the header of the method: public static int removeDuplicates(int[ ] A) For example, on input A=0, 0, 1, 1, 1, 2, 2, 3, 3, 4, your method should:...
Write a Java method that computes the future investment value at a given interest rate for...
Write a Java method that computes the future investment value at a given interest rate for a specified number of years. Your method should return the future investment value after calculation. The future investment is determined using the formula below:     futureInvestmentValue = investmentAmount * (1+monthlyInterestRate)numberOfYears*12 You can use the following method header: public static double futureInvestmentValue (double investmentAmount, double monthlyInterestRate, int years);
Decipher the following. They have been enciphered using a Shift Cipher with the given key. OMFMOAYNE,...
Decipher the following. They have been enciphered using a Shift Cipher with the given key. OMFMOAYNE, key = 12. TJNXWNVM, key = 19. LHAXEWJ, key = 22. DBSLEXO, key = 10. GDBPC ATVXDC, key =15. Decipher the following. They have been enciphered using a Shift Cipher with the given key. QSBHIFWCB, key = O. CQN ADKRLXW ARENA, key = J. ZKBYQD SQBUDTQH, key = Q. VTXLTKBTG LXVMBHG, key = T.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT