21bci0056 VL2023240503640 Ast01
21bci0056 VL2023240503640 Ast01
21bci0056 VL2023240503640 Ast01
Digital Assignment 1
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
import java.awt.Point;
import java.util.Scanner;
private PlayfairCipher()
//prompts user for the keyword to use for encoding & creates tables
while(key.equals(""))
key = parseString(sc);
table = this.cipherTable(key);
//prompts user for message to be encoded
while(input.equals(""))
input = parseString(sc);
this.keyTable(table);
this.printResults(output,decodedOutput);
//replaces any J's with I's and makes string all caps
parse = parse.toUpperCase();
return parse;
//creates the cipher table based on some input string (already parsed)
playfairTable[i][j] = "";
if(playfairTable[i][j].equals("" + keyString.charAt(k)))
repeat = true;
used = true;
return playfairTable;
//cipher: takes input (all upper-case), encodes it, and returns the output
in = in + "X";
encDigraphs = encodeDigraph(digraph);
return out;
//---------------encryption logic-----------------
//encodes the digraph input with the cipher's specifications
char a = di[i].charAt(0);
char b = di[i].charAt(1);
if(r1 == r2)
c1 = (c1 + 1) % 5;
c2 = (c2 + 1) % 5;
r1 = (r1 + 1) % 5;
r2 = (r2 + 1) % 5;
//executes if the letters of digraph appear in the different row and different column
//in such case swap the first column with the second column
else
c2 = temp;
//performs the table look-up and puts those values into the encoded array
return encipher;
//-----------------------decryption logic---------------------
// decodes the output given from the cipher and decode methods (opp. of encoding process)
char a = out.charAt(2*i);
char b = out.charAt(2*i+1);
if(r1 == r2)
c1 = (c1 + 4) % 5;
c2 = (c2 + 4) % 5;
r1 = (r1 + 4) % 5;
r2 = (r2 + 4) % 5;
}
else
//swapping logic
c1 = c2;
c2 = temp;
return decoded;
if(c == table[i][j].charAt(0))
pt = new Point(i,j);
return pt;
System.out.println();
System.out.print(printTable[i][j]+" ");
System.out.println();
System.out.println();
System.out.println(encipher);
System.out.println();
System.out.println(dec);
}
implement a program for encryption and decryption using Hill cipher substitution technique
Aimport java.util.Scanner;
import javax.swing.JOptionPane;
public static int[][] invkeymat = new int[][]{{ -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';
outtext += encrypt(ptextchars[i],ptextchars[i+1],ptextchars[i+2]);
outtext1 += decrypt(ptextchars1[i],ptextchars1[i+1],ptextchars1[i+2]);
int x,y, z;
a = key.charAt(x%26);
b = key.charAt(y%26);
int x,y,z;
a = key.charAt((x%26<0)?(26+x%26):(x%26));
b = key.charAt((y%26<0)?(26+y%26):(y%26));
return ret;
}
implement a program for encryption and decryption using Vigenere cipher substitution technique.
import java.util.Scanner;
String res="";
text=text.toUpperCase();
char c=text.charAt(i);
if(c<'A'||c>'z')
continue;
res+=(char)((c+key.charAt(j)-2*'A')%26+'A');
j=++j%key.length();
}
return res;
String res="";
text=text.toUpperCase();
for(int i=0,j=0;i<text.length();i++)
char c=text.charAt(i);
if(c<'A'||c>'z')
continue;
res+=(char)((c-key.charAt(j)+26)%26+'A');
j=++j%key.length();
return res;
try
String encryptedMsg=encrypt(message,key);
System.out.println("String :"+message);
catch(Exception e)
{
System.out.println(e);
}}}