From e26e6f4f980ea23b7b7bce6af3c1ea1b62285e7d Mon Sep 17 00:00:00 2001 From: skyouc Date: 星期六, 24 五月 2025 14:53:05 +0800 Subject: [PATCH] no message --- rsf-server/src/main/Test/ChineseMD5Util.java | 76 +++++++++++--------------------------- 1 files changed, 22 insertions(+), 54 deletions(-) diff --git a/rsf-server/src/main/Test/ChineseMD5Util.java b/rsf-server/src/main/Test/ChineseMD5Util.java index 963e6de..c73e2d3 100644 --- a/rsf-server/src/main/Test/ChineseMD5Util.java +++ b/rsf-server/src/main/Test/ChineseMD5Util.java @@ -1,70 +1,38 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; public class ChineseMD5Util { - /** - * 瀵规眽瀛楀瓧绗︿覆杩涜MD5鍔犲瘑 - * @param input 瑕佸姞瀵嗙殑姹夊瓧瀛楃涓� - * @return 32浣嶅皬鍐橫D5鍝堝笇鍊� - * @throws NoSuchAlgorithmException - */ - public static String md5Chinese(String input) throws NoSuchAlgorithmException { - if (input == null) { - return null; + public static List<Integer> getSelectedIndices(int[] arr) { + List<Integer> indices = new ArrayList<>(); + int index = 0; + int step = 3; + while (index < arr.length) { + indices.add(index); + index += step; + step = (step == 3) ? 1 : 3; } - - // 缁熶竴浣跨敤UTF-8缂栫爜 - byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8); - - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] digest = md.digest(inputBytes); - - // 灏嗗瓧鑺傛暟缁勮浆鎹负16杩涘埗瀛楃涓� - StringBuilder sb = new StringBuilder(); - for (byte b : digest) { - sb.append(String.format("%02x", b)); - } - - return sb.toString(); + return indices; } - /** - * 楠岃瘉姹夊瓧瀛楃涓蹭笌MD5鍝堝笇鏄惁鍖归厤 - * @param input 瑕侀獙璇佺殑姹夊瓧瀛楃涓� - * @param md5Hash 瀛樺偍鐨凪D5鍝堝笇鍊� - * @return 濡傛灉鍖归厤杩斿洖true锛屽惁鍒檉alse - */ - public static boolean verifyChinese(String input, String md5Hash) { - try { - String computedHash = md5Chinese(input); - return computedHash.equals(md5Hash.toLowerCase()); - } catch (NoSuchAlgorithmException e) { - // 鐞嗚涓婁笉浼氬彂鐢燂紝鍥犱负MD5鏄疛ava鏍囧噯搴撴敮鎸佺殑 - return false; + public static Integer getNextSelectedValue(int[] arr, int inputIndex) { + List<Integer> selectedIndices = getSelectedIndices(arr); + int currentPos = selectedIndices.indexOf(inputIndex); + if (currentPos != -1 && currentPos + 1 < selectedIndices.size()) { + return arr[selectedIndices.get(currentPos + 1)]; } + return null; // 鎴栨寜闇�澶勭悊 } public static void main(String[] args) { - try { - String chineseText = "浣犲ソ锛屼笘鐣岋紒"; + int[] arr = {2, 5, 8, 10, 15, 20, 25, 30, 35, 40, 45, 50, 15, 40, 32, 48}; + System.out.println("杈撳叆 0锛岃緭鍑�: " + getNextSelectedValue(arr, 0)); // 10 + System.out.println("杈撳叆 3锛岃緭鍑�: " + getNextSelectedValue(arr, 3)); // 15 + System.out.println("杈撳叆 4锛岃緭鍑�: " + getNextSelectedValue(arr, 4)); // 30 + System.out.println("杈撳叆 4锛岃緭鍑�: " + getNextSelectedValue(arr, 5)); // 30 - // 鍔犲瘑 - String md5Hash = md5Chinese(chineseText); - System.out.println("鍘熸枃: " + chineseText); - System.out.println("MD5鍝堝笇: " + md5Hash); - - // 楠岃瘉 - boolean isValid = verifyChinese(chineseText, md5Hash); - System.out.println("楠岃瘉缁撴灉: " + (isValid ? "鍖归厤" : "涓嶅尮閰�")); - - // 閿欒楠岃瘉绀轰緥 - boolean isWrongValid = verifyChinese("浣犲ソ锛屼笘鐣岋紒", md5Hash); - System.out.println("閿欒鏂囨湰楠岃瘉: " + (isWrongValid ? "鍖归厤" : "涓嶅尮閰�")); - - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } } } \ No newline at end of file -- Gitblit v1.9.1