예제 #1
0
        public VigenereOperation CipherGivenText(VigenereOperation vigenereOperation)
        {
            int mode = 0;

            int[] secretKeyNumberToMode = SecretKeyLetterToLetterNumbers(vigenereOperation);

            foreach (var character in vigenereOperation.plainText)
            {
                if (char.IsLetter(Convert.ToChar(character)))
                {
                    vigenereOperation.plainTextLetters = vigenereOperation.plainTextLetters + character;
                }
            }

            for (int i = 0; i < vigenereOperation.plainTextLetters.Length; i++)
            {
                for (int k = 0; k < 29; k++)
                {
                    if (vigenereOperation.alphabetToCipher[k + vigenereOperation.decipherAlphabetDecreaser] == vigenereOperation.plainTextLetters[i])
                    {
                        mode = (i) % (vigenereOperation.secretKey.Length);

                        vigenereOperation.CipherTextVigenere += vigenereOperation.alphabetToCipher[k + vigenereOperation.decipherAlphabetDecreaser + (vigenereOperation.cipherOrDecipher * (secretKeyNumberToMode[mode] + 1))];
                    }
                }
            }

            return(vigenereOperation);
        }
예제 #2
0
        private void btnDecipher_Click(object sender, EventArgs e)
        {
            VigenereOperation vigenereOperation = new VigenereOperation();
            CipherText        cipherText        = new CipherText();

            vigenereOperation.plainText                 = tbxCipherText.Text.ToLower().ToString();
            vigenereOperation.secretKey                 = tbxSecretKey.Text.ToLower().ToString();
            vigenereOperation.cipherOrDecipher          = -1;
            vigenereOperation.decipherAlphabetDecreaser = 29;

            vigenereOperation = cipherText.CipherGivenText(vigenereOperation);
            tbxPlainText.Text = vigenereOperation.CipherTextVigenere;
        }
예제 #3
0
        private void btnCipher_Click(object sender, EventArgs e)
        {
            VigenereOperation viginereOperation = new VigenereOperation();
            CipherText        cipherText        = new CipherText();

            viginereOperation.chiperWithSpace = cbxCipherWithSpace.Checked ? true : false;
            viginereOperation.plainText       = tbxPlainText.Text.ToLower().ToString();
            viginereOperation.secretKey       = tbxSecretKey.Text.ToLower().ToString();

            viginereOperation = cipherText.CipherGivenText(viginereOperation);

            tbxCipherText.Text        = viginereOperation.CipherTextVigenere;
            tbxKasiskiCipherText.Text = tbxCipherText.Text;
        }
예제 #4
0
        public int[] SecretKeyLetterToLetterNumbers(VigenereOperation vigenereOperation)
        {
            var secretKeyCharArray = vigenereOperation.secretKey.ToCharArray();

            int[] secretKeyLetterNumber = new int[secretKeyCharArray.Length];
            for (int k = 0; k < secretKeyCharArray.Length; k++)
            {
                for (int i = 0; i < 29; i++)
                {
                    if (secretKeyCharArray[k] == vigenereOperation.alphabetToCipher[i])
                    {
                        secretKeyLetterNumber[k] = i;
                    }
                }
            }

            return(secretKeyLetterNumber);
        }