Question

Vignere cipher.Suppose that I have the message One if by land and two if by...

Vignere cipher.

Suppose that I have the message One if by land and two if by sea and the key ABC To encrypt the message, conceptually we line up the key at the beginning of the message and then concatenate the message onto it, giving:

One if by land and two if by sea

ABC One if by land and two if by sea

 

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

import java.io.*;

import java.util.*;


class Cipher{

  public String encrypt(String msg,String key){

    String res = "";

    msg = msg.toUpperCase();

    int len = 0;

    char ch_len,ch_j;

    int j = 0;

    while (len < msg.length()){

      ch_len = msg.charAt(len);

      if ( (int)ch_len >= 65 && (int)ch_len <= 90 ){

        ch_j = msg.charAt(j);

        res += (char) (((int)ch_len + (int)ch_j - 2* (int)'A') % 26 + (int)'A');

        j += 1;

        j %= key.length();

      }

      len++;

    }

    return res;

  }

  

  public String decrypt(String msg,String key){

    String res = "";

    msg = msg.toUpperCase();

    int len = 0;

    char ch_len,ch_j;

    int j = 0;

    while (len < msg.length()){

      ch_len = msg.charAt(len);

      if ( (int)ch_len >= 65 && (int)ch_len <= 90 ){

        ch_j = msg.charAt(j);

        res += (char) (((int)ch_len - (int)ch_j + 26) % 26 + (int)'A');

        j += 1;

        j %= key.length();

      }

      len++;

    }

    return res;

  }

}


class main{

  public static void main(String[] args){

    String key = "VIGENERECIPHER";

    String message = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!";

    System.out.println("String L => " + message);

    

    Cipher c=new Cipher();

    String encryptedMsg = c.encrypt(message, key);

    System.out.println("Encrypted message => " + encryptedMsg);

    

    String decryptedMsg = c.decrypt(encryptedMsg, key);

    System.out.println("Decrypted message => " + decryptedMsg);   

  }

}


Add a comment
Know the answer?
Add Answer to:
Vignere cipher.Suppose that I have the message One if by land and two if by...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 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];                                                      ...

  • Q3: Suppose Bob wants to send an encrypted message to Alice. Which one of the followings...

    Q3: Suppose Bob wants to send an encrypted message to Alice. Which one of the followings is correct? 1. Bob uses a shared secret key to encrypt the message. Alice uses Bob's public key to decrypt the encrypted message. 2. Bob uses Alice's private key to encrypt the message. Alice uses a shared secret key to decrypt the encrypted message. 3. Bob uses Alice's public key to encrypt the message digest. Alice uses Bob's public key to decrypt the encrypted...

  • Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could...

    Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could you possibly make it as simple as you can without losing functionality. please include comments, that would help me better understand Example of PlayFair Cipher: https://en.wikipedia.org/wiki/Playfair_cipher The Playfair cipher uses a 5 by 5 table containing a key word or phrase. Memorization of the keyword and 4 simple rules was all that was required to create the 5 by 5 table and use the...

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

  • MASM Assembly language -- Message Encryption Pgm You are to write a program to input a...

    MASM Assembly language -- Message Encryption Pgm You are to write a program to input a text and a key and encrypt the text. I will supply you an encryption key consisting of multiple characters. Use this key to encrypt and decrypt the plain text by XOR-ing each character of the key against a corresponding byte in the message. Repeat the key as many times as necessary until all plain text bytes are translated. Suppose, for example, the key were...

  • I want to ask question about additive cipher The message is more secure if we encrypts...

    I want to ask question about additive cipher The message is more secure if we encrypts the message two times with additive cipher. Is this true or false? Why? thanks ~

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

  • Need help with number 3 the last one Need help with number 3 I have already...

    Need help with number 3 the last one Need help with number 3 I have already given the whole question MATH 1030 – Application Assignment 3 Cryptography Due: Thursday, June 4, 2020 at 11:59pm Atlantic time (submit through Brightspace) You must show your work for full marks. The goal of this assignment is to use our knowledge of linear algebra to do cryptography. We will encrypt a plaintext using a cipher where the resulting ciphertext should not be legible unless...

  • Some cryptography and a little computer security. You find an odd DeLorean parked around the corner....

    Some cryptography and a little computer security. You find an odd DeLorean parked around the corner. Realizing that Doc Brown has left the keys in the ignition, you decide that a quick trip back to Rome in 40 BC is in order. A few mint condition coins, and possibly a picture of Vincengetorix will be highly remunerative. As usual, the car fails and you are stranded. All is not lost, Julius Caesar recruits you for his secret service as a...

  • How to encrypt a string in C. I am using RSA encryption. I have a public...

    How to encrypt a string in C. I am using RSA encryption. I have a public and private key already. Public Key is (3,319) and private is (187,319) I have a string that says "I want to buy a gift". The person im sending this message to already has my public key. In C, how do encrpyt the string with my private key before I send it

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