package com.allianture.common.core;

/**
 * @author peter.li
 * @cretetime 2025-01-16 下午 02:31
 */

import org.bouncycastle.jcajce.provider.digest.Keccak;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * finallshell破解
 */
public class test {

    private static String hashMD5(String msg, String prefix, String suffix) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update((prefix + msg + suffix).getBytes(StandardCharsets.UTF_8));
        byte[] digest = md.digest();
        return bytesToHex(digest).substring(8, 24);
    }

    private static String hashKeccak384(String msg, String suffix) {
        Keccak.DigestKeccak keccak = new Keccak.Digest384();
        keccak.update((msg + suffix).getBytes(StandardCharsets.UTF_8));
        byte[] digest = keccak.digest();
        return bytesToHex(digest).substring(12, 28);
    }

    private static String bytesToHex(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }

    public static void generateActivationCodes(String code) {
        System.out.println("版本号 < 3.9.6 (旧版)");
        try {
            System.out.println("高级版: " + hashMD5(code, "61305", "8552"));
            System.out.println("专业版: " + hashMD5(code, "2356", "13593"));

            System.out.println("\n版本号 >= 3.9.6 (新版)");
            System.out.println("高级版: " + hashKeccak384(code, "hSf(78cvVlS5E"));
            System.out.println("专业版: " + hashKeccak384(code, "FF3Go(*Xvbb5s2"));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        //点击破解,
        String code = "123@acb33a27f243b843";
        generateActivationCodes(code);
    }
}