public static string decipherCText(string Text, char[] key) { int[] cText = new int[Text.Length]; for (int i = 0; i < Text.Length; i++) { cText[i] = Text[i]; } int[] plainText = new int[cText.Length]; if (key.Length == 0) { throw new Exception("Empty key"); } for (int i = 0; i <= plainText.Length / key.Length; i++) { for (int j = 0; j < key.Length; j++) { if ((key.Length * i + j) < cText.Length) { int xor = cText[key.Length * i + j] ^ key[j]; plainText[key.Length * i + j] = xor; } } } return(IntConversion.intsToHex(plainText)); }
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); }