Class PE0059

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] code
      A memory for the code
      private static double[] StandardDistribution
      Stores the standard distribution of letters in the English language
    • Constructor Summary

      Constructors 
      Constructor Description
      PE0059()
      A simple constructor to set number and title.
    • Method Summary

      Modifier and Type Method Description
      private byte[] decode​(byte[] code, byte[] key)
      Decodes a given code by the given key using a bitwise XOR operation.
      private double[] getLetterDist​(byte[] text)
      Calculates the distribution of all letters in the given text.
      void prepare()
      Prepares the problem by reading the code from a given file.
      java.lang.String solve()
      All possible keys from [aaa] to [zzz] are generated.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • StandardDistribution

        private static double[] StandardDistribution
        Stores the standard distribution of letters in the English language
      • code

        private byte[] code
        A memory for the code
    • Constructor Detail

      • PE0059

        public PE0059()
        A simple constructor to set number and title.
    • Method Detail

      • prepare

        public void prepare()
        Prepares the problem by reading the code from a given file.
        Specified by:
        prepare in interface Solvable
        Overrides:
        prepare in class Problem
      • solve

        public java.lang.String solve()
        All possible keys from [aaa] to [zzz] are generated. The code is decoded by every key and the distribution of letters is calculated for every of these decoded texts. The text with the smallest deviation is the solution.
        Returns:
        the sum of the ASCII codes of all letters in the decoded text
      • decode

        private byte[] decode​(byte[] code,
                              byte[] key)
        Decodes a given code by the given key using a bitwise XOR operation.
        Parameters:
        code - the code as array of bytes
        key - the key as array of bytes
        Returns:
        the decoded text as the result of decoding
      • getLetterDist

        private double[] getLetterDist​(byte[] text)
        Calculates the distribution of all letters in the given text. Both, lower and upper case versions of a letter, are counted as one.
        Parameters:
        text - the text to read the letters from
        Returns:
        an 26 elements big array with the relative count of each letter