@Override
public String encrypt(String st, int p) {
The interface does not need to add an abstract signature, because an interface is a pure abstract interface that is more abstract than an abstract class
Static variables or static methods of a class should not be accessed through the object reference of a class. There is no need to increase the parsing cost of the compiler. You can access them directly with the class name
while (true) {
System.out.println("This is a Caesar encryption/decryption program");
System.out.println("Press 1 to Encrypt or 2 to Decrypt");
System.out.println("Press 3 to calculate a string's MD5");
System.out.println("You can't Decrypt MD5,but you can press 4.");
int Operator;
String s;
int p;
Operator = scanner.nextInt();
if (Operator == 1) {
System.out.println("Step 1:Enter the string to encrypt.");
s = scanner.nextLine();
s = scanner.nextLine();
System.out.println("Step 2:Enter the offset.");
p = scanner.nextInt();
CaesarEncryption X = new CaesarEncryptioImpl();
s = X.Encrypt(s, p);
System.out.println(s);
}
if (Operator == 2) {
System.out.println("Step 1:Enter the string to decrypt.");
s = scanner.nextLine();
s = scanner.nextLine();
System.out.println("Step 2:Enter the offset.");
p = scanner.nextInt();
CaesarEncryption X = new CaesarEncryptioImpl();
s = X.Decrypt(s, p);
System.out.println(s);
}
if (Operator == 3) {
System.out.println("Enter the string to calculate MD5.");
System.out.println("The length of the result is 32.");
s = scanner.nextLine();
s = scanner.nextLine();
Md5Encryption X = new Md5Encryption();
s = X.backMD5(s);
System.out.println(s);
}
if (Operator == 4) {
Exception e = new UnsupportedOperationException();
e.printStackTrace();
System.out.println("UnsupportedOperationException");
System.out.println("异常信息: MD5 算法无法解密");
}
if (Operator > 4 || Operator < 1) {
break;
}
}
Do not submit .idea, target compie output directories and .iml file by using .gitignore file
Generally speaking, it's very good, except for some details. And you can continue to try to realize the advanced requirements. Please chat with me privately after the modification is completed.
@Override
at the beginning and please use loverCamelCase style for method nameabstract
signature, because aninterface
is a pure abstract interface that is more abstract than an abstract classif
/else
/for
/while
/do
statements, even if there is only one line of codeStringBuilder
type instead ofString
type when splicing strings to improve efficiencywhile
statement cannot be completed without throwing an exception.idea
,target
compie output directories and.iml
file by using.gitignore
file