Esempio n. 1
0
        //Hamming dist
        public static int hammingDist(string s1, string s2)
        {
            int dist = 0;


            int[] s1Ints = StringConverters.stringToInts(s1);
            int[] s2Ints = StringConverters.stringToInts(s2);


            if (s1Ints.Length != s2Ints.Length)
            {
                throw new Exception("Different lengths");
            }

            for (int i = 0; i < s1Ints.Length; i++)
            {
                int temp1 = s1Ints[i];
                int temp2 = s2Ints[i];


                for (int j = 0; j < 8; j++)
                {
                    if ((temp1 % 2) != (temp2 % 2))
                    {
                        dist++;
                    }

                    temp1 /= 2;
                    temp2 /= 2;
                }
            }


            return(dist);
        }
Esempio n. 2
0
        public static string crackMV(string hex)
        {
            string pText = "";

            int[] hexBytes = IntConversion.hexToInts(hex);

            int likelyKSize = findKeySize(hexBytes);

            List <int[]> transposedBlocks = transposeBlocks(hexBytes, likelyKSize);
            List <int[]> decipheredBlocks = new List <int[]>();

            for (int i = 0; i < transposedBlocks.Count; i++)
            {
                decipheredBlocks.Add(StringConverters.stringToInts(IntSingleVigenere.decipherCaesar(IntConversion.intsToHex(transposedBlocks[i])).Item3));
            }

            pText = IntConversion.intsToString(undoTranspose(decipheredBlocks));
            //Console.WriteLine(likelyKSize + " : " + pText);

            return(pText);
        }