/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.vutbr.feec.utko.fojtoval.krypto.funkce;

/**
 * Obsahuje metodu na vypocet IC nad zadanym textem.
 * @author fojtoval
 */
public class Ic extends Statistika {

    /**
     * Vypocet IC ze zadaneho textu.
     * @param text  vstupni text
     * @return IC
     */
    public static double ic (String text){

        int[]freq = new int[Constant.charNum];
        double indexcoincidency = 0;

        for(int i = 0; i < text.length(); i++) {
            freq[text.charAt(i)-'a']++;
        }

        for (int i = 0; i < Constant.charNum; i++) {
            indexcoincidency = indexcoincidency + Double.valueOf((freq[i]*(freq[i]-1)))/Double.valueOf((text.length()*(text.length()-1)));
        }

        return(indexcoincidency);

    }

}
