Ejemplo n.º 1
0
        public void Implement_CBC_mode_Test()  //CBC = Cipher Block Chaining
        {
            var BLOCKSIZE = 16;

            //https://cryptopals.com/sets/2/challenges/10
            string str   = Util.GetFile(10);
            string Hex   = MyConvert.Base64ToHex(str);
            var    bytes = MyConvert.HexToByteArray(Hex);

            //Initialization Vector (padded to BLOCKSIZE bytes)
            string IVHex   = Pad.PadHex(BLOCKSIZE * 2, "00");
            var    IVBytes = MyConvert.HexToByteArray(IVHex);

            //The Key
            string key      = "YELLOW SUBMARINE";
            string HexKey   = MyConvert.HexEncodePlainText(key);
            var    Keybytes = MyConvert.HexToByteArray(HexKey);

            //Perform my version of CBC
            var decryptedBytes = MyCrypto.AES_CBC_Decrypt(bytes, Keybytes, IVBytes, BLOCKSIZE);
            var HexResult      = MyConvert.BytesToHex(decryptedBytes);
            var Plain          = MyConvert.HexToAscii(HexResult);

            Assert.IsTrue("I'm back and I'm ringin' " == Plain.Substring(0, 25));  //25 is at least two blocks (of16) so i know i have the algo correct
        }
Ejemplo n.º 2
0
        public void Base64ToHex_Test()
        {
            string hexstring = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d";
            string Base64    = "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t";
            string Result    = MyConvert.Base64ToHex(Base64);

            Assert.IsTrue(hexstring == Result);
        }
Ejemplo n.º 3
0
        public void FixedXOR_Test2()
        {
            //https://cryptopals.com/sets/1/challenges/6
            string str          = Util.GetFile(6);
            string HextoDecrypt = MyConvert.Base64ToHex(str);
            var    Key          = "Terminator X: Bring the noise";
            var    HexKey       = Pad.PadKey(MyConvert.HexEncodePlainText(Key), HextoDecrypt.Length);
            var    DecryptedHex = MyCrypto.FixedXOR(HextoDecrypt, HexKey);
            var    Plain        = MyConvert.HexToAscii(DecryptedHex);

            Assert.IsTrue("I'm back and I'm ringin' " == Plain.Substring(0, 25));
        }
Ejemplo n.º 4
0
        public void AESinECB_Test()  //ECB = Electronic Codebook
        {
            //https://cryptopals.com/sets/1/challenges/7
            string str   = Util.GetFile(7);
            string Hex   = MyConvert.Base64ToHex(str);
            var    bytes = MyConvert.HexToByteArray(Hex);

            string key      = "YELLOW SUBMARINE";
            string HexKey   = MyConvert.HexEncodePlainText(key);
            var    Keybytes = MyConvert.HexToByteArray(HexKey);

            var result    = MyCrypto.AES_ECB_Decrypt(bytes, Keybytes);
            var HexResult = MyConvert.BytesToHex(result);
            var Plain     = MyConvert.HexToAscii(HexResult);

            Assert.IsTrue("I'm back and I'm ringin' " == Plain.Substring(0, 25));
        }