forked from mayank-joshi-99/Algorithm-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHillCipherEncrypt.java
More file actions
38 lines (31 loc) · 805 Bytes
/
HillCipherEncrypt.java
File metadata and controls
38 lines (31 loc) · 805 Bytes
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
import java.io.*;
import java.lang.*;
public class Main {
public static void main(String[] arg) throws Exception {
int k[][] = { { 2,1 }, { 3,4 } };
int p[] = new int[300];
int c[] = new int[300];
int i = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter plain text");
String str = br.readLine();
for (i = 0; i < str.length(); i++) {
int c1 = str.charAt(i);
p[i] = c1 - 97;
}
i = 0;
int zz = 0;
for (int b = 0; b < str.length() / 2; b++) {
for (int j = 0; j < 2; j++) {
for (int x = 0; x < 2; x++) {
c[i] += k[j][x] * p[x + zz];
}
i++;
}
zz += 2;
}
System.out.println("Encrypted Text : ");
for (int z = 0; z < str.length(); z++)
System.out.print((char) ((c[z] % 26) + 97));
}
}