1 Exp
1 Exp
a) Caesar Cipher
import java.u l.Scanner;
plainText = plainText.toLowerCase();
cipherText += replaceVal;
} else {
return cipherText;
cipherText = cipherText.toLowerCase();
if (keyVal < 0) {
plainText += replaceVal;
} else {
return plainText;
sc.close();
Output:
b) Playfair Cipher
import java.util.Scanner;
pfEncryption.makeArray(key);
pfEncryption.displayGrid();
msg = pfEncryption.manageMessage(msg);
pfEncryption.doPlayFair(msg, "Encrypt");
System.out.println("==================================");
pfEncryption.doPlayFair(encryptedText, "Decrypt");
class PFEncryption {
boolean present;
int val = 0;
present = false;
if (uniqueChar[j] == currentChar) {
present = true;
break;
uniqueChar[val] = currentChar;
val++;
isPresent = true;
break;
if (!isPresent) {
remainingChars.append(c);
uniqueChar[val] = remainingChars.charAt(i);
val++;
val = 0;
alphabets[i][j] = uniqueChar[val];
val++;
void displayGrid() {
System.out.print(alphabets[i][j] + "\t");
System.out.println();
}
newTxt.append(msg.charAt(i)).append('X');
i--;
} else {
newTxt.append(msg.charAt(i));
if (i + 1 < msg.length()) {
newTxt.append(msg.charAt(i + 1));
if (newTxt.length() % 2 != 0) {
newTxt.append('X');
return newTxt.toString();
if (alphabets[i][j] == ch1) {
row1 = i;
col1 = j;
row2 = i;
col2 = j;
if (tag.equals("Encrypt")) {
} else if (tag.equals("Decrypt")) {
if (row1 == row2) {
col1 = (col1 + 1) % 5;
col2 = (col2 + 1) % 5;
row2 = (row2 + 1) % 5;
} else {
if (row1 == row2) {
col1 = (col1 - 1 + 5) % 5;
col2 = (col2 - 1 + 5) % 5;
row1 = (row1 - 1 + 5) % 5;
row2 = (row2 - 1 + 5) % 5;
} else {
String getEncrypted() {
return encrypted;
String getDecrypted() {
return decrypted;
}
}
c) Hill Cipher
import java.util.Scanner;
import javax.swing.JOptionPane;
{ 1, 2, 1 },
{ 2, 3, 2 },
{ 2, 2, 1 }
};
{ -1, 0, 1 },
{ 2, -1, 0 },
{ -2, 2, -1 }
};
int ch, n;
text = sc.next();
text = text.toUpperCase();
n = text.length() % 3;
if (n != 0) {
text += "X";
}
int x, y, z;
ret = "" + a + b + c;
return ret;
}
int x, y, z;
ret = "" + a + b + c;
return ret;
}
d) Vigener Cipher
public class vigenercipher1 {
text = text.toUpperCase();
char c = text.charAt(i);
continue;
j = ++j % key.length();
return res;
text = text.toUpperCase();
char c = text.charAt(i);
continue;
j = ++j % key.length();
return res;
}
public static void main(String[] args) {