Question

How to write a program in order to find the key? Given a ciphertext message that...

How to write a program in order to find the key?

Given a ciphertext message that was generated using the XOR cipher and a bit string found in the plaintext, find the key that can be used to map the plaintext to the ciphertext. The key size is 32 bits.

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

using java program:

import java.io.*;
import javax.swing.JOptionPane;
  
   public class XOR
   {
  
        public static void main(String[] args)
        {
          
            String str = (JOptionPane.showInputDialog("Input Plaintext:"));
           
          
         String str1 = (JOptionPane.showInputDialog("Input ciphertext:"));
            int Length=str1.length();
                
           
            //prints key
            String key = key(str,Length);
            System.out.println("key:" + key);
  
          
        }
  
        public static String key(String str, int Length)
        {
            String key = "";
            for(int i = 0; i < str.length(); i++)
            {
                int c = str.charAt(i);
               
                if (Character.isUpperCase(c))
                {
                    //26 letters of the alphabet so mod by 26
                    c = c + (Length % 26);
                    if (c > 'Z')
                    c = c - 26;
                }
                else if (Character.isLowerCase(c))
                {
                    c = c + (Length % 26);
                    if (c > 'z')
                    c = c - 26;
                }
                key += (char) c;
            }
        return key;
        }
         
   }

Add a comment
Know the answer?
Add Answer to:
How to write a program in order to find the key? Given a ciphertext message that...
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
  • Example 5.1 How many padding bits must be added to a message of 100 characters if 8-bit ASCII is ...

    please explain how they solved this. in a simple way. Example 5.1 How many padding bits must be added to a message of 100 characters if 8-bit ASCII is used for encoding and the block cipher accepts blocks of 64 bits? Solution Encoding 100 characters using 8-bit ASCII results in an 800-bit message. The plaintext must be divisible by 64. If MI and IPadl are the length of the message and the length of the padding 32 mod 64 This...

  • Substitution Cipher Ke 1. Decipher the following ciphertext using the substitution cipher key shown above: (4 points) Ciphertext: DOVMYWOJAYJMYWZBAOXOADY!U I Plaintext: The following information was...

    Substitution Cipher Ke 1. Decipher the following ciphertext using the substitution cipher key shown above: (4 points) Ciphertext: DOVMYWOJAYJMYWZBAOXOADY!U I Plaintext: The following information was extracted from The BLACK Chamber's Pigpen Cipher page. The content is available at https:/simonsingh net The_Black Chamber'pigpen html. "The Pigpen Cipher was used by Freemasons in the l8th Century to keep their records private. The cipher does not substitute one letter for another; rather it substitutes each letter for a symbol The aiphabet is written...

  • 1. Encrypt the message howareyou using the affine cipher using the key (7,3). (a) What is...

    1. Encrypt the message howareyou using the affine cipher using the key (7,3). (a) What is the resulting ciphertext? (b) What is the decryption function you can use to decipher each ciphertext character? (c) Use your decryption function to decrypt the message to confirm you get the ciphertext back. 2. Use the ADFGX cipher using the grid below and the keyword "place" to encrypt the plaintext "brandenburggate". FREE GX (a) (b) What is the resulting ciphertext? How does the ADFGC...

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

    Write a javascript program which implements the following two classical cryptosystem which we covered in class: Affine Cipher Vigenere Cipher Your program should consist of at least five functions: 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. Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string and a key as...

  • Computer science encryption please refer to the chart to help For the remaining questions, consider a...

    Computer science encryption please refer to the chart to help For the remaining questions, consider a 4-bit block cipher, described in hexadecimal by the following table: Plaintext Ciphertext Plaintext Ciphertext 4 You can think of this as a simple substitution cipher for hexadecimal digits. The table itself serves as the "key" s (6 pts) For this question, you will perform encryption and 5. decryption using the same cipher described above, but in CBC mode. Recall that you can convert hexadecimal...

  • 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...

  • Q1: Given a message “explanations” a) Define a key, which is a combination of last names...

    Q1: Given a message “explanations” a) Define a key, which is a combination of last names of all team members. For example, for a team of two persons ‘John Smith’ and ‘John Li’ the key will be ‘SmithLi’. You will use this key for encryption and decryption below b) First encrypt the message using Vigenère cipher. Encrypt the resulting cipher-text using Playfair cipher. c)Decrypt the ciphertext from part b above. Hint: First decrypt using Playfair cipher and then decrypt it...

  • 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...

  • the w 2. This problem explores the use of a one-time pad version of t In...

    the w 2. This problem explores the use of a one-time pad version of t In this scheme, the key is a stream of random numbers between 0 and example, if the key is 3 19 5..., then the first letter of plaintext is encrypted with a shift of 3 letters, the second with a shift of 19 letters, the third with a shift of 5 letters, and so on. a. Encrypt the plaintext sendmoremoney with the key stream 9...

  • 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...

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