You are on page 1of 2

import java.util.

*;
import java.util.Scanner;

public class transWithoutKey {

public static void main(String args[]) {


Scanner scan = new Scanner(System.in);

System.out.print("Type your Message : ");


String message = scan.nextLine();

int start=0;
String s="";

for(int i=0;i<message.length();i++) {
if(message.charAt(i)==' ') {
s=s+message.substring(start,i);
start=i+1;
}
}
s=s+message.substring(start);

int msgchar = s.length();

if (!((msgchar % 4) == 0)) {

do {
s = s + " ";
msgchar = s.length();
} while (!((msgchar % 4) == 0));

}
String ans = "";

char temp[][] = new char[4][s.length()];


char msg[] = s.toCharArray();
int x = 0;
int y = 0;
for (int i = 0; i < msg.length; i++) {
if (msg[i] == ' ')
temp[x][y] = ' ';
else
temp[x][y] = msg[i];
if (y == (4 - 1)) {
y = 0;
x = x + 1;
} else {
y++;
}
}

System.out.println();
for (int j = 0; j < x; j++) {
for (int i = 0; i < 4; i++) {
System.out.print(temp[j][i]+" ");
ans+=temp[i][j];
}
System.out.println();
}
System.out.println("----- result of encryption -----\n");
System.out.println(ans);
System.exit(0);
}

private static int find(String key, char c) {

for (int i = 0; i < key.length(); i++) {


if (key.charAt(i) == c) {
return i;
}
}
return 0;
}
}

You might also like