How do I solve the encryption & decryption with ‘g’ and ‘z’.
here’s the java program—>
import java.io.*;
class morse
{
public static void main(String args[])throws IOException
{
BufferedReader kybd=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 1 to encrypt or 2 to decyrpt");
int length=3;
char dot[]={'E',' ','B'};
char comma[]={'Z','C','X'};
char ques[]={'V','N','M'};
char a[]={'#','$','%'};
char b[]={'^','>','<'};
char c[]={'!','@','&'};
char d[]={'*','(',')'};
char e[]={'`','~','-'};
char f[]={'_','=','+'};
char g[]={'R','T','U'};
char h[]={'{','}','|'};
char I[]={',','.','/'};
char j[]={'c','z','?'};
char k[]={'x','v','W'};
char l[]={'n','m','b'};
char m[]={'a','d','s'};
char n[]={'g','h','f'};
char o[]={'j','k','l'};
char p[]={'"',';',':'};
char q[]={'q','e','w'};
char r[]={'t','y','r'};
char s[]={'u','p','i'};
char t[]={'1','2','o'};
char u[]={'4','3','5'};
char v[]={'8','7','9'};
char w[]={'G','P','6'};
char x[]={'A','O','Q'};
char y[]={'S','J','I'};
char z[]={'F','H','R'};
char space[]={'Y','L','D','K'};
int choice=Integer.parseInt(kybd.readLine());
if(choice==1)
{
System.out.println("Enter the message to be encrypted");
String str1=kybd.readLine();
String str=str1.toLowerCase();
System.out.println();
for(int i=0;i<str1.length();i++)
{
if(str.charAt(i)==' ')
{
System.out.print(space[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='.')
{
System.out.print(dot[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)==',')
{
System.out.print(comma[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='?')
{
System.out.print(ques[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='a')
{
System.out.print(a[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='b')
{
System.out.print(b[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='c')
{
System.out.print(c[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='d')
{
System.out.print(d[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='e')
{
System.out.print(e[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='f')
{
System.out.print(f[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='g')
{
System.out.print(g[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='h')
{
System.out.print(h[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='i')
{
System.out.print(I[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='j')
{
System.out.print(j[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='k')
{
System.out.print(k[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='l')
{
System.out.print(l[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='m')
{
System.out.print(m[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='n')
{
System.out.print(n[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='o')
{
System.out.print(o[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='p')
{
System.out.print(p[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='q')
{
System.out.print(q[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='r')
{
System.out.print(r[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='s')
{
System.out.print(s[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='t')
{
System.out.print(t[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='u')
{
System.out.print(u[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='v')
{
System.out.print(v[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='w')
{
System.out.print(w[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='x')
{
System.out.print(x[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='y')
{
System.out.print(y[(int)(Math.random()*(length-0.1))]);
}
if(str.charAt(i)=='z')
{
System.out.print(z[(int)(Math.random()*(length-0.1))]);
}
}
}
else
{
System.out.println("Enter the message to be decrypted");
String dec=kybd.readLine();
System.out.println();
System.out.print(" The decrypted message is----> ' ");
for(int i=0;i<dec.length();i++)
{
if((dec.charAt(i)=='E')||(dec.charAt(i)==' ')||(dec.charAt(i)=='B'))
{
System.out.print(".");
}
if((dec.charAt(i)=='Z')||(dec.charAt(i)=='C')||(dec.charAt(i)=='X'))
{
System.out.print(",");
}
if((dec.charAt(i)=='V')||(dec.charAt(i)=='N')||(dec.charAt(i)=='M'))
{
System.out.print("?");
}
if((dec.charAt(i)=='#')||(dec.charAt(i)=='$')||(dec.charAt(i)=='%'))
{
System.out.print("a");
}
if((dec.charAt(i)=='^')||(dec.charAt(i)=='>')||(dec.charAt(i)=='<'))
{
System.out.print("b");
}
if((dec.charAt(i)=='!')||(dec.charAt(i)=='@')||(dec.charAt(i)=='&'))
{
System.out.print("c");
}
if((dec.charAt(i)=='*')||(dec.charAt(i)=='(')||(dec.charAt(i)==')'))
{
System.out.print("d");
}
if((dec.charAt(i)=='`')||(dec.charAt(i)=='~')||(dec.charAt(i)=='-'))
{
System.out.print("e");
}
if((dec.charAt(i)=='_')||(dec.charAt(i)=='=')||(dec.charAt(i)=='+'))
{
System.out.print("f");
}
if((dec.charAt(i)=='R')||(dec.charAt(i)=='T')||(dec.charAt(i)=='U'))
{
System.out.print("g");
}
if((dec.charAt(i)=='{')||(dec.charAt(i)=='}')||(dec.charAt(i)=='|'))
{
System.out.print("h");
}
if((dec.charAt(i)==',')||(dec.charAt(i)=='.')||(dec.charAt(i)=='/'))
{
System.out.print("i");
}
if((dec.charAt(i)=='c')||(dec.charAt(i)=='z')||(dec.charAt(i)=='?'))
{
System.out.print("j");
}
if((dec.charAt(i)=='x')||(dec.charAt(i)=='v')||(dec.charAt(i)=='W'))
{
System.out.print("k");
}
if((dec.charAt(i)=='n')||(dec.charAt(i)=='m')||(dec.charAt(i)=='b'))
{
System.out.print("l");
}
if((dec.charAt(i)=='a')||(dec.charAt(i)=='d')||(dec.charAt(i)=='s'))
{
System.out.print("m");
}
if((dec.charAt(i)=='g')||(dec.charAt(i)=='h')||(dec.charAt(i)=='f'))
{
System.out.print("n");
}
if((dec.charAt(i)=='j')||(dec.charAt(i)=='k')||(dec.charAt(i)=='l'))
{
System.out.print("o");
}
if((dec.charAt(i)=='"')||(dec.charAt(i)==';')||(dec.charAt(i)==':'))
{
System.out.print("p");
}
if((dec.charAt(i)=='q')||(dec.charAt(i)=='e')||(dec.charAt(i)=='w'))
{
System.out.print("q");
}
if((dec.charAt(i)=='t')||(dec.charAt(i)=='y')||(dec.charAt(i)=='r'))
{
System.out.print("r");
}
if((dec.charAt(i)=='u')||(dec.charAt(i)=='p')||(dec.charAt(i)=='i'))
{
System.out.print("s");
}
if((dec.charAt(i)=='1')||(dec.charAt(i)=='2')||(dec.charAt(i)=='o'))
{
System.out.print("t");
}
if((dec.charAt(i)=='4')||(dec.charAt(i)=='3')||(dec.charAt(i)=='5'))
{
System.out.print("u");
}
if((dec.charAt(i)=='8')||(dec.charAt(i)=='7')||(dec.charAt(i)=='9'))
{
System.out.print("v");
}
if((dec.charAt(i)=='G')||(dec.charAt(i)=='P')||(dec.charAt(i)=='6'))
{
System.out.print("w");
}
if((dec.charAt(i)=='A')||(dec.charAt(i)=='O')||(dec.charAt(i)=='Q'))
{
System.out.print("x");
}
if((dec.charAt(i)=='S')||(dec.charAt(i)=='J')||(dec.charAt(i)=='I'))
{
System.out.print("y");
}
if((dec.charAt(i)=='F')||(dec.charAt(i)=='H')||(dec.charAt(i)=='R'))
{
System.out.print("z");
}
if((dec.charAt(i)=='Y')||(dec.charAt(i)=='L')||(dec.charAt(i)=='D')||(dec.charAt(i)=='K'))
{
System.out.print(" ");
}
}
System.out.print(" ' ");
}
}
}