-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransCipher.java
More file actions
61 lines (60 loc) · 1.08 KB
/
TransCipher.java
File metadata and controls
61 lines (60 loc) · 1.08 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
51
52
53
54
55
56
57
58
59
60
61
import java.util.*;
class TransCipher
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the plain text");
String pl = sc.nextLine();
sc.close();
String s =
""; int start
= 0;
for (int i = 0; i < pl.length(); i++)
{ if (pl.charAt(i) == ' ') {
s = s + pl.substring(start, i);
start = i + 1;
}
}
s = s + pl.substring(start);
System.out.print(s);
System.out.println();
// end of space deletion
int k =
s.length(); int l =
0;
int col = 4;
int row = s.length() / col;
char ch[][] = new char[row]
[col]; for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{ if (l < k) {
ch[i][j] =
s.charAt(l); l++;
} else {
ch[i][j] = '#';
}
}
}
// arranged in matrix
char trans[][] = new char[col]
[row]; for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
{ trans[j][i] = ch[i][j];
}
}
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++)
{
System.out.print(trans[i][j]);
}
}
// display
System.out.println();
}
}
OUTPUT:
Enter the plain
text Security Lab
SecurityLab
Sreictuy