package org.jeecg.module.custom.ocr.utils;

public class HashCompareUtil {

    public static String cmpHash(String hash1,String hash2){
        int n = 0;
        // hash长度不同则返回-1代表传参出错
        if (hash1.length() != hash2.length()){
            return "-1";
        }
        for(int i = 0; i < hash1.length(); i++){
            if( hash1.charAt(i) != hash2.charAt(i)){
                n=n + 1;
            }
        }
        String formattedResult="";
        double c=100.0 - n/64.0 * 100.0;
        if (c % 1 == 0) {
            // 如果是整数，将小数位去除
            formattedResult = String.valueOf((int) c);
        } else {
            // 如果不是整数，保留两位小数
            formattedResult = String.valueOf(Math.round(c));
        }
        return formattedResult;
    }


    public static void main(String[] args) {
        String a="1111111100000111000110110001101100110011001100000000000011110001";
        String b="1111111100000111000110110001101100110011001100000000000011110001";
        long start = System.currentTimeMillis();
        int ss=0;
//        for(int i=0;i<5000000;i++){
//            String a="1111111100000111000110110001101100110011001100000000000011110001"+i;
//            String b="1011111100000111000110110001101100110011001100000000000011110001"+i;
        String dd = HashCompareUtil.cmpHash(a, b);
        System.out.println(dd);
//            ss=i;
//        }
    }
}
