每日一练_02:
编写一个程序对输入的内容进行加密,也可以对输入的内容进行解密。
import java.util.*;
public class encryptionAndDecryption{
public static void main(String args[]){
System.out.println("Please enter the file you want to encrypt:");
Scanner scanner = new Scanner(System.in);
String password = scanner.nextLine();
char secret = 'A';
char []a = password.toCharArray();
for(int i=0;i<a.length;i++){
a[i]=(char)(a[i]^secret);
}
System.out.println("It is encrypted as shown below:");
for(int i=0;i<a.length;i++){
System.out.print(a[i]);
}
System.out.println("");
System.out.println("enter what you want to decrypt:");
String password2 = scanner.nextLine();
char []b = password2.toCharArray();
for(int i=0;i<b.length;i++){
b[i]=(char)(b[i]^secret);
}
System.out.println("It is decrypted as shown below:");
for(int i=0;i<b.length;i++){
System.out.print(b[i]);
}
}
}
结果如下:
Please enter the file you want to encrypt:
十点进攻
It is encrypted as shown below:
匀烸辚敺
enter what you want to decrypt:
匀烸辚敺
It is decrypted as shown below:
十点进攻
大家好,今天编写的是大佬给本菜鸟的第二道编程题。结合了课本内容,抠jio完成,欢迎大家提出好的建议。