src/test/java/org/nyu/crypto/HillClimberTest.java
@Test
    @SuppressWarnings("unchecked")
    public void validateClimbingKeyScorePlaintextDigraph() {

        int positive = 0;
        int negative = 0;

        Simulation simulation = simulator.createSimulation();
        String plaintext = simulation.getMessage();

        // now compute plaintext digraph for our experiment
        double[][] digraph = digrapher.computeDictionaryDigraph();

        Climb climb = hillClimber.climb(simulation.getCiphertext(), digraph);
        String putative = climb.getPutative();

        HashMap<String, ArrayList<Integer>> key = mapper.convertValue(simulation.getKey(), HashMap.class);
        HashMap<String, ArrayList<Integer>> ikey = climb.getInitialKey();
        HashMap<String, ArrayList<Integer>> pkey = climb.getPutativeKey();

        logger.info("initial key: ");
        keyGenerator.printKey(ikey);

        logger.info("putative key: ");
        keyGenerator.printKey(pkey);


        // score of initial key guess against actual key
        int iscore = 0;
        for (String keyval : ikey.keySet()) {
            ArrayList<Integer> ilist = ikey.get(keyval);
            ArrayList<Integer> list = key.get(keyval);
            for (Integer i : ilist) {
                if (list.contains(i)) {
                    logger.info("matched <" + keyval + " : " + i + "> in initial");
                    iscore++;
                }
            }
        }

        // score of putative key against actual key
        int pscore = 0;
        for (String keyval : pkey.keySet()) {
            ArrayList<Integer> plist = pkey.get(keyval);
            ArrayList<Integer> list = key.get(keyval);
            for (Integer i : plist) {
                if (list.contains(i)) {
                    logger.info("matched <" + keyval + " : " + i + "> in putative");
                    pscore++;
                }
            }
        }

        // score of putative key should always be greater or equal to the initial key
        logger.info("initial key score: " + iscore);
        logger.info("putative key score: " + pscore);

        logger.info("putative : " + putative);
        logger.info("plaintext: " + plaintext);

        if (pscore > iscore) positive++;
        else negative++;

        logger.info(positive + " | " + negative);
         // assert positive > negative;
    }
/**
     * TODO - write tests to compare key and putative key similarity!
     */
write tests to compare key and putative key similarity!
write tests to compare key and putative key similarity!
@Test
    @SuppressWarnings("unchecked")
    public void validateClimbingKeyScorePlaintextDigraph() {
        int positive = 0;
        int negative = 0;
        Simulation simulation = simulator.createSimulation();
        String plaintext = simulation.getMessage();
        double[][] digraph = digrapher.computeDictionaryDigraph();
        Climb climb = hillClimber.climb(simulation.getCiphertext(), digraph);
        String putative = climb.getPutative();
        HashMap<String, ArrayList<Integer>> key = mapper.convertValue(simulation.getKey(), HashMap.class);
        HashMap<String, ArrayList<Integer>> ikey = climb.getInitialKey();
        HashMap<String, ArrayList<Integer>> pkey = climb.getPutativeKey();
        logger.info("initial key: ");
        keyGenerator.printKey(ikey);
        logger.info("putative key: ");
        keyGenerator.printKey(pkey);
        int iscore = 0;
        for (String keyval : ikey.keySet()) {
            ArrayList<Integer> ilist = ikey.get(keyval);
            ArrayList<Integer> list = key.get(keyval);
            for (Integer i : ilist) {
                if (list.contains(i)) {
                    logger.info("matched <" + keyval + " : " + i + "> in initial");
                    iscore++;
                }
            }
        }
        int pscore = 0;
        for (String keyval : pkey.keySet()) {
            ArrayList<Integer> plist = pkey.get(keyval);
            ArrayList<Integer> list = key.get(keyval);
            for (Integer i : plist) {
                if (list.contains(i)) {
                    logger.info("matched <" + keyval + " : " + i + "> in putative");
                    pscore++;
                }
            }
        }
        logger.info("initial key score: " + iscore);
        logger.info("putative key score: " + pscore);
        logger.info("putative : " + putative);
        logger.info("plaintext: " + plaintext);
        if (pscore > iscore) positive++;
        else negative++;
        logger.info(positive + " | " + negative);
    }
@ Test @ SuppressWarnings ( "unchecked" ) public void validateClimbingKeyScorePlaintextDigraph ( ) { int positive = 0 ; int negative = 0 ; Simulation simulation = simulator . createSimulation ( ) ; String plaintext = simulation . getMessage ( ) ; double [ ] [ ] digraph = digrapher . computeDictionaryDigraph ( ) ; Climb climb = hillClimber . climb ( simulation . getCiphertext ( ) , digraph ) ; String putative = climb . getPutative ( ) ; HashMap < String , ArrayList < Integer > > key = mapper . convertValue ( simulation . getKey ( ) , HashMap . class ) ; HashMap < String , ArrayList < Integer > > ikey = climb . getInitialKey ( ) ; HashMap < String , ArrayList < Integer > > pkey = climb . getPutativeKey ( ) ; logger . info ( "initial key: " ) ; keyGenerator . printKey ( ikey ) ; logger . info ( "putative key: " ) ; keyGenerator . printKey ( pkey ) ; int iscore = 0 ; for ( String keyval : ikey . keySet ( ) ) { ArrayList < Integer > ilist = ikey . get ( keyval ) ; ArrayList < Integer > list = key . get ( keyval ) ; for ( Integer i : ilist ) { if ( list . contains ( i ) ) { logger . info ( "matched <" + keyval + " : " + i + "> in initial" ) ; iscore ++ ; } } } int pscore = 0 ; for ( String keyval : pkey . keySet ( ) ) { ArrayList < Integer > plist = pkey . get ( keyval ) ; ArrayList < Integer > list = key . get ( keyval ) ; for ( Integer i : plist ) { if ( list . contains ( i ) ) { logger . info ( "matched <" + keyval + " : " + i + "> in putative" ) ; pscore ++ ; } } } logger . info ( "initial key score: " + iscore ) ; logger . info ( "putative key score: " + pscore ) ; logger . info ( "putative : " + putative ) ; logger . info ( "plaintext: " + plaintext ) ; if ( pscore > iscore ) positive ++ ; else negative ++ ; logger . info ( positive + " | " + negative ) ; }
TODO - write tests to compare key and putative key similarity!
TODO - write tests to compare key and putative key similarity!
// now compute plaintext digraph for our experiment // score of initial key guess against actual key // score of putative key against actual key // score of putative key should always be greater or equal to the initial key // assert positive > negative;