Esempio n. 1
0
        public void DecryptOneCharD()
        {
            char[] alphabet   = Caesar.GetAlphabet();
            string cipherText = Caesar.Decrypt(3, "d");

            Assert.AreEqual("a", cipherText, "Error in decrypting a single character at beginning of alphabet");
        }
Esempio n. 2
0
 private string DecodeS(string code, string encodedMessage)
 {
     if (code == "B")
     {
         Base64 B = new Base64();
         return(B.Decode(encodedMessage));
     }
     else if (code == "R")
     {
         ROT13 ROT = new ROT13();
         return(ROT.Decode(encodedMessage));
     }
     else if (code == "T")
     {
         ROT18 ROT = new ROT18();
         return(ROT.Decode(encodedMessage));
     }
     else if (code == "C")
     {
         Caesar c = new Caesar();
         return(c.Decode(encodedMessage));
     }
     else
     {
         return("Error");
     }
 }
Esempio n. 3
0
        public void EncryptTwoCharYZ()
        {
            char[] alphabet   = Caesar.GetAlphabet();
            string cipherText = Caesar.Encrypt(3, "yz");

            Assert.AreEqual("ab", cipherText, "Error in encrypting two characters at end of alphabet");
        }
Esempio n. 4
0
    private void ClientConnected(object sender, Server.ClientConnectedEventArgs e)
    {
        Console.WriteLine("Client connected");
        var caesar = new Caesar {
            Alphabet = "abcdefghijklmnopqrstuvwxyzåäö",
            Shift    = 0
        };

        using (var stream = e.Client.GetStream())
            using (var reader = new StreamReader(stream, Encoding.UTF8))
                using (var writer = new StreamWriter(stream, Encoding.UTF8)) {
                    while (!reader.EndOfStream)
                    {
                        var received = reader.ReadLine();

                        for (caesar.Shift = 0; caesar.Shift < caesar.Alphabet.Length; caesar.Shift++)
                        {
                            writer.WriteLine(caesar.Decipher(received));
                        }

                        writer.WriteLine();
                        writer.Flush();
                    }
                }

        e.Client.Close();

        Console.WriteLine("Client disconnected");
    }
Esempio n. 5
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            #region li
            linkLabel1.Hide();
            linkLabel2.Hide();
            linkLabel3.Hide();
            linkLabel4.Hide();
            linkLabel5.Hide();

            #endregion
            if (searchText.Text == " " || searchText.Text == "")
            {
                Caesar.speakerError();
            }
            else
            {
                ricerca.elementoRicerca = searchText.Text;
                searchText.Text         = "Sto cercando ...";
                Ricerca();
                Caesar.speaker(ricerca.elementoRicerca);
                #region li
                linkLabel1.Text = ricerca.urls[0];
                linkLabel2.Text = ricerca.urls[1];
                linkLabel3.Text = ricerca.urls[2];
                linkLabel4.Text = ricerca.urls[3];
                linkLabel5.Text = ricerca.urls[4];

                linkLabel1.Show();
                linkLabel2.Show();
                linkLabel3.Show();
                linkLabel4.Show();
                linkLabel5.Show();
                #endregion
            }
        }
Esempio n. 6
0
        private void Button_Clicked(object sender, EventArgs e)
        {
            CryptLibrary.ICryptService ser = new Caesar();
            OutputPage p = new OutputPage();

            InputText.Text = ser.Crypt(InputText.Text, KeyInput.Text);
        }
Esempio n. 7
0
        private void DecryptButton_Click(object sender, EventArgs e)
        {
            if (EncryptedText.TextLength < 1)
            {
                return;
            }

            switch (AlgorithmSelect.SelectedIndex)
            {
            case 0:
                var caesar = new Caesar((int)caesarShift.Value, string25Key.Text);
                NormalText.Text = caesar.Decrypt(EncryptedText.Text);
                break;

            case 1:
                var playfaire = new Playfair(string25Key.Text);
                NormalText.Text = playfaire.Decrypt(EncryptedText.Text);
                break;

            case 2:
                var rsa = new RSA(rsaPublicText.Text, rsaPrivateText.Text);
                NormalText.Text = rsa.Decrypt(EncryptedText.Text);
                break;


            default:
                break;
            }
        }
Esempio n. 8
0
        public void EncryptOneCharZ()
        {
            char[] alphabet   = Caesar.GetAlphabet();
            string cipherText = Caesar.Encrypt(3, "z");

            Assert.AreEqual("b", cipherText, "Error in encrypting a single character at end of alphabet");
        }
Esempio n. 9
0
        public void EncryptTwoCharAB()
        {
            char[] alphabet   = Caesar.GetAlphabet();
            string cipherText = Caesar.Encrypt(3, "ab");

            Assert.AreEqual("de", cipherText, "Error in encrypting two characters at beginning of alphabet");
        }
Esempio n. 10
0
        public void DecryptAndThenDecryptALongPhrase()
        {
            char[] alphabet      = Caesar.GetAlphabet();
            string decryptedText = Caesar.Decrypt(3, Caesar.Encrypt(3, "What is the square root of a duck"));

            Assert.AreEqual("what is the square root of a duck", decryptedText, "Error in encrypting and then decrypting a long phrase");
        }
Esempio n. 11
0
        public void DecryptAndThenDecryptASingleWordFollowedBySpace()
        {
            char[] alphabet      = Caesar.GetAlphabet();
            string decryptedText = Caesar.Decrypt(3, Caesar.Encrypt(3, "What "));

            Assert.AreEqual("what ", decryptedText, "Error in encrypting and then decrypting a single word followed by a space");
        }
Esempio n. 12
0
        public void DecryptAndThenDecryptOneChar()
        {
            char[] alphabet      = Caesar.GetAlphabet();
            string decryptedText = Caesar.Decrypt(3, Caesar.Encrypt(3, "d"));

            Assert.AreEqual("d", decryptedText, "Error in encrypting and then decrypting a single character at beginning of alphabet");
        }
Esempio n. 13
0
        public void EncryptPhraseWithShift200()
        {
            char[] alphabet   = Caesar.GetAlphabet();
            string cipherText = Caesar.Encrypt(290, "One Love");

            Assert.AreEqual("hgytehoy", cipherText, "Error in encrypting a phrase with shift 20");
        }
Esempio n. 14
0
        public void EncryptOneWordAllCaps()
        {
            char[] alphabet   = Caesar.GetAlphabet();
            string cipherText = Caesar.Encrypt(3, "MOOSEPOOP");

            Assert.AreEqual("prrvhsrrs", cipherText, "Error in encrypting one word all caps");
        }
Esempio n. 15
0
        public void EncryptPhraseWithShift3()
        {
            char[] alphabet   = Caesar.GetAlphabet();
            string cipherText = Caesar.Encrypt(3, "One Love");

            Assert.AreEqual("rqhcoryh", cipherText, "Error in encrypting a phrase with shift 3");
        }
Esempio n. 16
0
        public void SetUp()
        {
            _caesar = new Caesar(8);

            _plainText     = "Das sind nicht die Droiden, die Ihr sucht!";
            _encryptedText = "LiAhAqvlhvqkpBhlqmhLzwqlmv(hlqmhQpzhACkpBf";
        }
        public static void Descifrado(string path, string root, string palabra)
        {
            string descomprimido = "";
            string directorio;

            directorio = root + @"\\Upload\\";
            if (!Directory.Exists(directorio + "\\Caesar\\"))
            {
                DirectoryInfo di = Directory.CreateDirectory(directorio + "\\Caesar\\");
            }
            string texto         = System.IO.File.ReadAllText(@path);
            Caesar descifrado    = new Caesar(palabra, texto);
            string txtdescifrado = descifrado.Descifrado();

            txtdescifrado = txtdescifrado.Replace("┼", "");
            txtdescifrado = txtdescifrado.Replace("↔", "");
            root          = root + @"\\Upload\\Caesar\\descifradoCaesar.txt";
            using (StreamWriter outputFile = new StreamWriter(root))
            {
                foreach (char caracter in txtdescifrado)
                {
                    outputFile.Write(caracter.ToString());
                }
            }
        }
Esempio n. 18
0
        public void CaesarCryptIsSuccessful()
        {
            const string THE_QBF         = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG";
            const string THE_QBF_SHIFT23 = "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD";

            string cipherText, plainText;

            cipherText = Caesar.EncryptASCII("ABC", 1);
            Assert.AreEqual("BCD", cipherText, "ABC not encrypted correctly");

            cipherText = Caesar.EncryptASCII("abc", 1);
            Assert.AreEqual("bcd", cipherText, "abc not encrypted correctly");

            cipherText = Caesar.EncryptASCII("XYZ", 1);
            Assert.AreEqual("YZA", cipherText, "XYZ not encrypted correctly");

            cipherText = Caesar.EncryptASCII("xyz", 1);
            Assert.AreEqual("yza", cipherText, "xyz not encrypted correctly");

            cipherText = Caesar.EncryptASCII(THE_QBF, 23);
            Assert.AreEqual(THE_QBF_SHIFT23, cipherText, "THE QUICK BROWN FOX FAILED AND FLOPPED.");

            plainText = Caesar.DecryptASCII("BCD", 1);
            Assert.AreEqual("ABC", plainText, "BCD not decrypted correctly");

            plainText = Caesar.DecryptASCII("bcd", 1);
            Assert.AreEqual("abc", plainText, "bcd not decrypted correctly");

            plainText = Caesar.DecryptASCII(THE_QBF_SHIFT23, 23);
            Assert.AreEqual(THE_QBF, plainText, "Fail: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD");
        }
Esempio n. 19
0
        private static void Decrypt()
        {
            string cipherText = ReadFile();

            string plainText = Caesar.Decrypt(_key, cipherText);

            WriteFile(plainText);
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            ICryptService service = new Caesar();
            string        cr      = service.Crypt("Hello world", "1");

            Console.WriteLine(cr);
            string dcr = service.Decrypt(cr, "2");

            Console.WriteLine(dcr);
        }
Esempio n. 21
0
    static string vigenereEncrypt(string plainText, string key)
    {
        string[] cipherParts = split(plainText, key.Length); //split in k parts
        for (int i = 0; i < key.Length; i++)                 //encrypt every part with appropriate shifting factor
        {
            cipherParts[i] = Caesar.caesarEncrypt(cipherParts[i], key[i] - indexOfLetter(key[i]));
        }

        return(mergeParts(cipherParts));        //merge the encrypted parts
    }
Esempio n. 22
0
        public void EncryptDecryptBasic()
        {
            Caesar cipher           = new Caesar(15);
            var    intermediaryText = cipher.Encrypt(TestString);

            Assert.AreNotEqual(TestString, intermediaryText);
            var plainText = cipher.Decrypt(intermediaryText);

            Assert.AreEqual(TestString, plainText);
        }
Esempio n. 23
0
        public void CipherEncryptsThenDecryptsToSamePhrase()
        {
            string phrase = "All Tests Work";
            int    shift  = 5;

            Caesar caesar = new Caesar();

            string actualResult = caesar.Decrypt(caesar.Encrypt(phrase, shift), shift);

            Assert.AreEqual(phrase, actualResult);
        }
        public IActionResult Post([FromBody] EncryptedMessage message)
        {
            var alphabet      = message.Alphabet;
            var encryptedText = message.EncryptedText;

            Caesar cipher = new Caesar(alphabet);

            message.EncryptedText = cipher.Decrypt(encryptedText);

            return(Json(message));
        }
Esempio n. 25
0
        public void CaesarCipher_RetunsEncryptedString()
        {
            //Arrange
            Caesar caesar = new Caesar();

            //Act
            string result = caesar.Encrypt("xyz", 2);

            //Assert
            Assert.That(result, Is.EqualTo("zab"));
        }
Esempio n. 26
0
        public void CipherCorrectlyEncriptsWithSimpleShift()
        {
            string phrase         = "Ashened";
            int    shift          = 11;
            string expectedResult = "Ldspypo";

            Caesar caesar = new Caesar();

            string actualResult = caesar.Encrypt(phrase, shift);

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 27
0
        public void CipherIgnoresNonLetterCharacters()
        {
            string phrase         = "J3110 Y0t1f#$`)";
            int    shift          = -24;
            string expectedResult = "H3110 W0r1d#$`)";

            Caesar caesar = new Caesar();

            string actualResult = caesar.Decrypt(phrase, shift);

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 28
0
        public void CipherWorksWithLargerShift()
        {
            string phrase         = "Hello World";
            int    shift          = 15634;
            string expectedResult = "Pmttw Ewztl";

            Caesar caesar = new Caesar();

            string actualResult = caesar.Encrypt(phrase, shift);

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 29
0
        public void CipherCorrectlyDecrypts()
        {
            string phrase         = "CzggjFdoot";
            int    shift          = 21;
            string expectedResult = "HelloKitty";

            Caesar caesar = new Caesar();

            string actualResult = caesar.Decrypt(phrase, shift);

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 30
0
        public void CipherCorrectlyEncriptsWithNegativeShift()
        {
            string phrase         = "HelloKitty";
            int    shift          = -15;
            string expectedResult = "SpwwzVteej";

            Caesar caesar = new Caesar();

            string actualResult = caesar.Encrypt(phrase, shift);

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 31
0
    public static void Main(string [] args)
    {
        string wort, verschluesselt, entschluesselt;
        int key;

        Console.WriteLine("Eingabe Wort: ");
        wort = Console.ReadLine();

        Console.WriteLine("Eingabe Schlüssel: ");
        key = Int32.Parse(Console.ReadLine());

        Caesar c = new Caesar();

        verschluesselt = c.verschluesseln(wort, key);
        Console.WriteLine("\n\nVerschlüsselt: {0} ({1}) -> {2}", wort, key, verschluesselt);

        entschluesselt = c.entschluesseln(verschluesselt, key);
        Console.WriteLine("Entschlüsselt: {0} ({1}) -> {2}\n", verschluesselt, key, entschluesselt);

        if(entschluesselt == wort ) {
            Console.WriteLine("\nDie Verschlüsselung / Entschlüsselung funktioniert!\n");
        }
    }