コード例 #1
0
        private void BreakSimpleXorEncryption(object sender, EventArgs e)
        {
            var str = System.IO.File.ReadAllText("Files\\6.txt");

            str            = CryptoTools.BreakRepeatingKeyXor(str);
            txtOutput.Text = str;
        }
コード例 #2
0
        private void DetectXor(object sender, EventArgs e)
        {
            var xord               = new List <string>();
            var highestScore       = 0;
            var encryptionChar     = (byte)0;
            var textToDecrypt      = string.Empty;
            var lineScore          = 0;
            var lineEncryptionChar = (byte)0;

            for (var i = 0; i < txtDetectXor.Lines.Length; i++)
            {
                var str = txtDetectXor.Lines[i];
                CryptoTools.FindAndDecode(str, out lineScore, out lineEncryptionChar);
                if (lineScore > highestScore)
                {
                    highestScore   = lineScore;
                    encryptionChar = lineEncryptionChar;
                    textToDecrypt  = str;
                }
                xord.Add(string.Format("{0} {1} {2}", lineScore, lineEncryptionChar, str));
            }
            txtDetectXor.Lines = xord.ToArray();

            var y = encryptionChar.Xor(textToDecrypt.AsHexToByteArray());

            lblDetectXor.Text = Encoding.UTF8.GetString(y);
        }
コード例 #3
0
        private void ScoreXor(object sender, EventArgs e)
        {
            var  highestScore   = 0;
            byte encryptionChar = (byte)0;

            txtXorScoreResults.Text = CryptoTools.FindAndDecode(txtXorScore.Text, out highestScore, out encryptionChar);
        }
コード例 #4
0
        private void DecryptAesEcb(object sender, EventArgs e)
        {
            var str            = System.IO.File.ReadAllText("Files\\7.txt");
            var ba             = Convert.FromBase64String(str);
            var key            = Encoding.UTF8.GetBytes("YELLOW SUBMARINE");
            var decryptedArray = CryptoTools.DecryptAesEcb(key, ba);

            txtOutput.Text = Encoding.UTF8.GetString(decryptedArray);
        }
コード例 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            var txt = System.IO.File.ReadAllText("Files\\10.txt");
            var ba  = Convert.FromBase64String(txt);

            ba = CryptoTools.PadToMultiple(ba, 16);
            var key = Encoding.UTF8.GetBytes("YELLOW SUBMARINE");

            txtOutput.Text = CryptoTools.CbcDecrypt(key, new byte[16], ba);
        }
コード例 #6
0
        private void PadText(object sender, EventArgs e)
        {
            var source     = Encoding.UTF8.GetBytes(txtPadSrc.Text);
            var multipleOf = Convert.ToInt32(txtPadMultiple.Text);
            var str        = Encoding.UTF8.GetString(CryptoTools.PadToMultiple(source, multipleOf));

            txtOutput.Text = Regex.Replace(str,
                                           @"\p{Cc}",
                                           a => string.Format("\\x{0:X2}", (byte)a.Value[0])
                                           );
        }
コード例 #7
0
        public static string FindAndDecode(byte[] source, out int highestScore, out byte encryptionChar)
        {
            highestScore = 0;
            var highestScoreText = string.Empty;

            encryptionChar = (byte)0;
            for (var i = 0; i <= 255; i++)
            {
                var resArray = i.Xor(source);
                var score    = CryptoTools.CountPrintables(resArray);
                if (score > highestScore)
                {
                    highestScore     = score;
                    highestScoreText = Encoding.UTF8.GetString(resArray);
                    encryptionChar   = (byte)i;
                }
            }
            return(highestScoreText);
        }
コード例 #8
0
 private void GetHammingDistance(object sender, EventArgs e)
 {
     lblHamming.Text = CryptoTools.HammingDistance(txtHamming1.Text, txtHamming2.Text).ToString();
 }