Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Java program that will cryptographically encode a message. The program

ID: 3629830 • Letter: C

Question

Create a Java program that will cryptographically encode a message. The program will first ask a user to enter the secret "key," which it will use to encrypt the messages that are typed in next. The key will be needed to decrypt the messages, but you will not have to write the decryption method.

Your program will use a simple substitution cypher, that is, each letter that is typed in will be substituted by the appropriate letter in the key. A space will not be encrypted, so it will remain a space.

The output should look something like this:
Enter the key as a random ordering of the 26 letters of the English alphabet
0: b
1: w
2: y
3: a
4: c
5: g
6: e
7: i
8: k
9: m
10: o
11: q
12: s
13: u
14: z
15: x
16: v
17: t
18: r
19: p
20: n
21: l
22: j
23: h
24: f
25: d

Enter the message to be encrypted: hello spy
The encrypted message is: icqqz rxf

Enter the message to be encrypted: bye
The encrypted message is: wfc

Enter the message to be encrypted: ace of diamonds
The encrypted message is: byc zg akbszuar

Enter the message to be encrypted:
Goodbye!

Explanation / Answer

please rate - thanks

import java.util.*;
public class main
{public static void main(String[] args) {
char[]let=new char[26];
int i,j;
Scanner in=new Scanner(System.in);
char c;
String input;
boolean found;
for(i=0;i<26;i++)
    let[i]=' ';
System.out.println("Enter the key as a random ordering of the 26 letters of the English alphabet");
i=0;
while(i<26)
   {found=false;
    System.out.print(i+":");
    c=in.next().charAt(0);
    for(j=0;j<26;j++)
         {if(c==let[j])
              {System.out.println(c+" already used");
                found=true;
                }
            }   
    if(!found)
        {let[i]=c;
        i++;
        }
    }

in.nextLine();
System.out.print("Enter the message to be encrypted: ");       
input=in.nextLine();
while(input.length()>0)
{System.out.print("The encrypted message is: ");
   for(i=0;i<input.length();i++)
       {j=(int)input.charAt(i);
        if(j>=97&&j<=122)
             System.out.print(let[j-97]);
        else
             System.out.print(" ");
        }
   System.out.print(" Enter the message to be encrypted: ");       
   input=in.nextLine();
}
System.out.println("Goodbye!");
}
}