Question Details

(solution) import java.util.Scanner; import javax.crypto.SecretKey; import


Need help with this java assignment it is 3 method returning values to 2 other method


import java.util.Scanner;

 

import javax.crypto.SecretKey;

 

import javax.crypto.spec.SecretKeySpec;

 

/**

 

*

 

*/

 

import java.util.Scanner;

 

/**

 

* @author Sanchd

 

*

 

*/

 

public class Vigenere {

 

private static final int LETTERS_IN_ALPHABET = 26;

 

private static final int ASCII_RANGE = 256;

 

/**

 

* @param args

 

*/

 

public static void main(String args) {

 

// TODO Get the user inputs. a message of several words and punctuation.

 

Scanner plaintext = new Scanner(System.in);

 

System.out.println("Enter a multi-word message with punctuation");

 

String text = plaintext.nextLine();

 

System.out.println("Enter a single word key with not punctuations");

 

String key = plaintext.nextLine();

 

String encryptedText = encrypt(text, key);

 

System.out.println("String: " + text);

 

System.out.println("the encode message is:

 

System.out.println("the decoded message is:

 

key));

 

} " + encryptedText);

 

" + decrypt(encryptedText, static String encrypt(String text, String key) {

 

StringBuilder t = new StringBuilder();

 

String k = key;

 

char square = createVigSquare();

 

for (int i = 0, j = 0; i < text.length(); i++, j++) {

 

if (j >= key.length()) {

 

j = 0;

 

}

 

t.append(square[k.charAt(j)][text.charAt(i)]);

 

}

 

} return t.toString(); static String decrypt(String text, String key) {

 

StringBuilder t = new StringBuilder();

 

String k = key; char square = createVigSquare();

 

for (int i = 0; i < k.length(); i++) {

 

//char index = 'a';

 

int rowIndex = k.charAt(i);

 

char row = square[rowIndex];

 

int colIndex = new String(row).indexOf(text.charAt(i));

 

t.append((char) colIndex);

 

}

 

} return t.toString(); static char createVigSquare() {

 

char square = new char[ASCII_RANGE][ASCII_RANGE];

 

int start = 'a';

 

int end = start + (LETTERS_IN_ALPHABET - 1);

 

int index = start;

 

for (int i = start; i <= end; i++) {

 

for (int j = start; j <= end; j++) {

 

if (index > end) {

 

index = start;

 

}

 

square[i][j] = (char) index;

 

index++;

 

}

 

} index = i + 1; return square;

 

}

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

//

 

} static int getColIndex(char vigSquare, char ch) {

 

int index = 0;

 

// //TODO Return the column index of the

 

// character, ch, in the message to be encripted

 

return index;

 

}

 

static int getRowIndex(char vigSquare, char keyCh) {

 

// Return the row index of the next

 

// character, keyCh, in the key

 

}

 

static char getPlainTextChar(char vigSquare, int rowIndex, char ch) {

 

// Return the plaintext character

 

// corresponding to the ciphertext

 

// character 'ch' from the square

 

return ch;

 

}

 


Solution details:

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Sep 13, 2020

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN A DEADLINE.

Order Now