class Encryption { protected String wordM; protected String phrase;
public Encriptacion(){
}
public Encriptacion(String palabraM, String frase){
this.palabraM=palabraM;
this.frase=frase;
}
public boolean setPalabraM(String palabraM){
if(palabraM.length()>=4 || palabraM.length()<=6){
this.palabraM=palabraM;
return true;
}else{
System.out.println("Palabra erronea");
}
return false;
}
public String getPalabraM(){
return palabraM;
}
public void setFrase(String frase){
this.frase= frase;
}
public String getFrase(){
return frase;
}
}
class Encrypt extends Encryption {
private String palabraM;
private String frase;
public Encriptar(){
}
public Encriptar(String palabraM, String frase){
super(palabraM, frase);
}
public void hacerEncriptacion(){
int cont = 0;
char arreglo [][]=null;
System.out.println(frase.length());
System.out.println(palabraM.length());
int div=((int)(frase.length()/palabraM.length()));
System.out.println(div);
if(frase.length()%palabraM.length()!=0){
div++;
}
System.out.println(div);
arreglo = new char [palabraM.length()][div];
for(int j=0;j<div; j++){
for(int i=0; i<palabraM.length();i++){
if(cont<frase.length()){
arreglo[i][j]=frase.charAt(cont);
}else{
arreglo[i][j]='*';
}
cont++;
}
}
for(int i=0;i<arreglo.length;i++ ){
for(int j=0; j<div;j++){
System.out.print(arreglo[i][j]);
}
System.out.println();
}
}
}
import java.util.Scanner; class FARGPIA { public static void main (String args []) { int option, option2; String wordM; String phrase;
Scanner sc = new Scanner(System.in);
Encriptacion encriptacion =new Encriptacion();
Desencriptar desc = new Desencriptar();
Encriptar enc= new Encriptar();
do{
System.out.println("Ingrese la opcion deseada");
System.out.println("1. Desencriptar");
System.out.println("2. Encriptar");
System.out.println("3. Salir");
opcion = sc.nextInt();
switch (opcion){
case 1:
System.out.println("Ingrese la frase");
sc.nextLine();
frase= sc.nextLine();
encriptacion.setFrase(frase);
System.out.println();
do{
System.out.println("Ingrese la palabra magica");
palabraM= sc.next();
encriptacion.setPalabraM(palabraM);
}while(desc.setPalabraM(palabraM)!=true);
System.out.println();
desc.hacerDesencriptacion();
break;
case 2:
System.out.println("Ingrese la frase");
sc.nextLine();
frase= sc.nextLine();
encriptacion.setFrase(frase);
System.out.println();
do{
System.out.println("Ingrese la palabra magica");
sc.nextLine();
palabraM= sc.next();
}while(enc.setPalabraM(palabraM)!=true);
encriptacion.setPalabraM(palabraM);
System.out.println();
enc.hacerEncriptacion();
break;
case 3:
break;
}
System.out.println();
}while(opcion!=3);
}
}