-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEncryption.java
More file actions
executable file
·51 lines (47 loc) · 1.26 KB
/
Encryption.java
File metadata and controls
executable file
·51 lines (47 loc) · 1.26 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
import java.util.Scanner;
/**
* Encryption
*/
public class Encryption {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
String S="";
for (int i = 0; i < s.length(); i++) {
char c=s.charAt(i);
if(c!=' '){
S+=c;
}
}
int L=S.length();
int row=(int)Math.floor(Math.pow(L, 0.5));
int column=(int)Math.ceil(Math.pow(L, 0.5));
if((row*column)<L){
row++;
}
char encryt[][]=new char[row][column];
int p=0;
for (int i = 0; i < row; i++) {//storing
for (int j = 0; j < column; j++) {
try {
encryt[i][j]=S.charAt(p);
} catch (Exception e) {
encryt[i][j]='\u0000';
}
p++;
}
}
String result="";
for (int i = 0; i < column; i++) {
int j = 0;
for (; j < row; j++) {
if(!(encryt[j][i]=='\u0000'))
result+=encryt[j][i];
}
if(!(i==column-1))
result+=" ";
}
System.out.print(result);
sc.close();
}
}