Question: JAVA HELP Can anyone tell me why the strings are not printing anything out when these functions are called. Code is part of a Vingenere

JAVA HELP

Can anyone tell me why the strings are not printing anything out when these functions are called. Code is part of a Vingenere Ci[her program:

static String encrypt(String text, String key) {

// Using the key, encode the message

// and return the encoded message

StringBuilder t = new StringBuilder();

String k = key;

char vigSquare[][] = createVigSquare();// create vigSquare

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

if (Character.isLetter(text.charAt(i)))// if char at i is letter

{

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

j = 0;// if j reached to length of the key then set j=0

}

// then append char at i in text

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

} else// if char at i is not a letter

t.append(text.charAt(i));// then simple append char

}

return t.toString();

}

static String decrypt(String encryptedText, String key) {

// Using the key,

// decode the encoded message and

// return the original message in lowercase

StringBuilder t = new StringBuilder();

String k = key;

char[][] vigSquare = createVigSquare();// create vigSquare

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

if (Character.isLetter(encryptedText.charAt(i)))// if char at i is letter

{

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

j = 0;// if j reached to length of the key then set j=0

}

int rowIndex = k.charAt(j++);

char[] row = vigSquare[rowIndex];// get row from vigSquare

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

t.append((char) colIndex);// then append asscii value of index

} else// if char at i is not a letter

t.append(encryptedText.charAt(i));// then simple apppend char

}

return t.toString();// return decrypted message

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!