import io.swagger.models.auth.In;
import tech.glinfo.enbao.common.utils.ByteUtils;

import java.util.Arrays;
import java.util.Collections;

public class MqttTest {
    public static void main(String[] args) {
        for(int i=4; i<10; i++) {
            String sn = "002EB21223020"+i;

            String n = sn.substring(5);
//            String[] ns = n.split("");
//            String[] ons = new String[9];
//            System.arraycopy(ns, 0, ons, 0, ns.length);
//            Arrays.sort(ns, Collections.reverseOrder());
//            System.out.println(Arrays.toString(ons));
//            System.out.println(Arrays.toString(ns));
            encrypt(n);
        }

        String topic = "sys/002EB212230201/data/up";
        String[] strings = topic.split("/");
        System.out.println(strings[1]);

        String aa = "2B021C643430393135313461353434620E30314345423232383830303030310C54502D4C494E4B5F39333244";
        String mac = ByteUtils.hexToString(aa.substring(8, 32));
        Integer length = Integer.valueOf(aa.substring(32, 34), 16);
        String wifi = ByteUtils.hexToString(aa.substring(34, 34+length*2));
        System.out.println(mac);
        System.out.println(length);
        System.out.println(wifi);
    }

    public static String encrypt(String sn) {
        String[] ns = sn.split("");
        int len = ns.length;
        String[] ons = new String[len];
        System.arraycopy(ns, 0, ons, 0, ns.length);
        Arrays.sort(ns, Collections.reverseOrder());
        System.out.println(Arrays.toString(ons));
//        System.out.println(Arrays.toString(ns));
        int sum = 0;
        int[] is = new int[len];
        for(int i=0; i < len; i++) {
            int a = Integer.valueOf(ns[i]);
            int b = Integer.valueOf(ons[i]);
            is[i] = a ^ b;
            sum += is[i];
        }
//        System.out.println(sum);
        char[] pwd = new char[len];
        for(int i=0; i<len; i++) {
            int temp = (i + sum + is[i]) % 26 + 97;
//            System.out.println(temp);
            pwd[i] = (char) temp;
//            System.out.println(pwd[i]);
//            System.out.print(new Character(pwd[i]).toString());
        }
        System.out.println(String.valueOf(pwd));
        return null;
    }
}
