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 }
public void AESinCBC_Encrypt_Decrypt_Test() //CBC = Cipher Block Chaining { int BLOCKSIZE = 16; string OriginalMessage = "Now I rock a house party at the drop of a hat\nAnd I beat a body down with an aluminum bat"; var bytes = MyConvert.TextToByteArray(OriginalMessage); var PaddedBytes = Pad.AddPkcs7(bytes, 128); //Pad the message to 128 bytes //The Key (16 bytes) string key = "YELLOW SUBMARINE"; string HexKey = MyConvert.HexEncodePlainText(key); var Keybytes = MyConvert.HexToByteArray(HexKey); //Initialization Vector (padded to BLOCKSIZE bytes) string IVHex = Pad.PadHex(BLOCKSIZE * 2, "00"); var IVBytes = MyConvert.HexToByteArray(IVHex); //Encrypt var CiperBytes = MyCrypto.AES_CBC_Encrypt(PaddedBytes, Keybytes, IVBytes, BLOCKSIZE); //Decrypt var PlainBytes = MyCrypto.AES_CBC_Decrypt(CiperBytes, Keybytes, IVBytes, BLOCKSIZE); var UnPaddedBytes = Pad.RemovePkcs7(PlainBytes); //Unpad the message var hexPlain = MyConvert.BytesToHex(UnPaddedBytes); var PlainText = MyConvert.HexToAscii(hexPlain); Assert.IsTrue(OriginalMessage == PlainText); }
public void GetHammingDistance_Test() { //https://cryptopals.com/sets/1/challenges/6 string test = "this is a test"; string woka = "wokka wokka!!!"; var TestHex = MyConvert.HexEncodePlainText(test); var WokaHex = MyConvert.HexEncodePlainText(woka); int HamDist = Stats.GetHammingDistance(TestHex, WokaHex); Assert.IsTrue(HamDist == 37); }
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)); }
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)); }
public void AESinECB_Encrypt_Decrypt_Test() //ECB = Electronic Codebook { string OriginalMessage = "Now is the time for all good men to come to the aid of their country"; var bytes = MyConvert.TextToByteArray(OriginalMessage); var PaddedBytes = Pad.AddPkcs7(bytes, 128); //Pad the message to 128 bytes //The Key (16 bytes) string key = "YELLOW SUBMARINE"; string HexKey = MyConvert.HexEncodePlainText(key); var Keybytes = MyConvert.HexToByteArray(HexKey); //Encrypt var CiperBytes = MyCrypto.AES_ECB_Encrypt(PaddedBytes, Keybytes); //Decrypt var PlainBytes = MyCrypto.AES_ECB_Decrypt(CiperBytes, Keybytes); var UnPaddedBytes = Pad.RemovePkcs7(PlainBytes); //Unpad the message var hexPlain = MyConvert.BytesToHex(UnPaddedBytes); var PlainText = MyConvert.HexToAscii(hexPlain); Assert.IsTrue(OriginalMessage == PlainText); }