-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHillCipher.java
More file actions
51 lines (49 loc) · 1.31 KB
/
Copy pathHillCipher.java
File metadata and controls
51 lines (49 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
public class HillCipher {
public static void main(String[] args) {
// TODO code application logic here
int [][]a={{6,24,1},{13,16,10},{20,17,15}};
int [][]b={{8,5,10},{21,8,21},{21,12,8}};
int i,j, t=0;
int []c=new int[40];
int []d=new int[40];
System.out.println("Enter the plain text");
Scanner sc=new Scanner(System.in);
String txt=sc.next();
char k[];
k=txt.toCharArray();
int []l=new int[9];
for(i=0;i<txt.length();i++){
l[i]=k[i]-65;
System.out.println(l[i]);
}
for(i=0;i<3;i++)
{
t=0;
for(j=0;j<3;j++)
{
t=t+(a[i][j]*l[j]);
}
d[i]=t%26;
}
System.out.println("\nEncrypted Cipher Text :");
for(i=0;i<3;i++){
char m=(char) ((char)d[i]+65);
System.out.print(m);
}
for(i=0;i<3;i++)
{
t=0;
for(j=0;j<3;j++){
t=t+(b[i][j]*d[j]);
}
c[i]=t%26;
}
System.out.println("\nDecrypted Cipher Text :");
for(i=0;i<3;i++){
char m=(char) ((char)c[i]+65);
System.out.print(m);
}
System.out.println();
}
}