题解 | #字符串加解密#
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import java.util.*; public class Main { static String plainDict = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; static String encryptDict = "BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza1234567890"; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String plainText = scanner.nextLine(); System.out.println(encrypt(plainText)); String encrypted = scanner.nextLine(); System.out.println(decrypt(encrypted)); } private static String encrypt(String plainText){ StringBuilder sb = new StringBuilder(); for (char ch : plainText.toCharArray()) { sb.append(encryptDict.charAt(plainDict.indexOf(ch))); } return sb.toString(); } private static String decrypt(String encrypted){ StringBuilder sb = new StringBuilder(); for (char ch : encrypted.toCharArray()) { sb.append(plainDict.charAt(encryptDict.indexOf(ch))); } return sb.toString(); } }