public void SerpentCipherConstructorTest() { byte[] key = null; // TODO: Initialize to an appropriate value CipherMode mode = null; // TODO: Initialize to an appropriate value CipherPadding padding = null; // TODO: Initialize to an appropriate value SerpentCipher target = new SerpentCipher(key, mode, padding); Assert.Inconclusive("TODO: Implement code to verify target"); }
private void bgwDecrypt_DoWork(object sender, DoWorkEventArgs e) { serpent = new SerpentCipher { AlphabetLength = 256 }; // tworzę instancję klasy szyfrującej w drugim wątku programu i inicjalizuję długość alfabetu serpent.EncryptionProgressChanged += MainWindow_EncryptionProgressChanged; // dodaję własny event handler obsłgująct pasek stanu operacji var key = (byte[])((object[])e.Argument)[0]; var sourceFile = ((object[])e.Argument)[1].ToString(); var rounds = (int)((object[])e.Argument)[2]; var algMode = (Mode)((object[])e.Argument)[3]; var encrMode = (EncryptionMode)((object[])e.Argument)[4]; var flag = serpent.Decrypt(sourceFile, key, rounds, algMode, encrMode); e.Result = flag; // przekazuję informację czy deszyfrowanie się powiodło do zdarzenia, które jest wykonywane następnie. }
private void bgwEncrypt_DoWork(object sender, DoWorkEventArgs e) { serpent = new SerpentCipher { AlphabetLength = 256 }; serpent.EncryptionProgressChanged += MainWindow_EncryptionProgressChanged; var key = (byte[])((object[])e.Argument)[0]; var sourceFile = ((object[])e.Argument)[1].ToString(); var rounds = (int)((object[])e.Argument)[2]; var algMode = (Mode)((object[])e.Argument)[3]; var encrMode = (EncryptionMode)((object[])e.Argument)[4]; var flag = serpent.Encrypt(sourceFile, key, rounds, algMode, encrMode); e.Result = flag; }
public void EncryptBlockTest() { byte[] key = null; // TODO: Initialize to an appropriate value CipherMode mode = null; // TODO: Initialize to an appropriate value CipherPadding padding = null; // TODO: Initialize to an appropriate value SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value byte[] inputBuffer = null; // TODO: Initialize to an appropriate value int inputOffset = 0; // TODO: Initialize to an appropriate value int inputCount = 0; // TODO: Initialize to an appropriate value byte[] outputBuffer = null; // TODO: Initialize to an appropriate value int outputOffset = 0; // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
private ICryptoTransform CreateCryptoTransform(byte[] rgbKey, byte[] rgbIV, bool encrypt) { if (rgbKey == null) { rgbKey = this.Key; } else if (!ValidKeySize(rgbKey.Length * 8)) { throw new ArgumentException("Invalid key size"); } if (rgbIV != null && rgbIV.Length * 8 > BlockSize) { throw new ArgumentException("Invalid IV size"); } SerpentCipher cipher = new SerpentCipher(rgbKey, Helper.ShouldEncrypt(this, encrypt)); return(Helper.CreateCryptoTransform(this, cipher, encrypt, rgbIV)); }
static void Main(string[] args) { DESAlgorithm des = new DESAlgorithm(); TripleDES tripleDES = new TripleDES(); SerpentCipher serpent = new SerpentCipher(); AESAlgorithm aes = new AESAlgorithm(); Stopwatch sWatch = new Stopwatch(); for (; ;) { Console.WriteLine("Выберите алгоритм шифрования"); Console.WriteLine("1 Алгоритм DES"); Console.WriteLine("2 Алгоритм DES3"); Console.WriteLine("3 Алгоритм AES"); Console.WriteLine("4 Алгоритм Twofish"); Console.WriteLine("5 Алгоритм Serpent"); int choose = Convert.ToInt32(Console.ReadLine()); switch (choose) { case 1: { s = ""; string key = "Безопасность"; sWatch.Start(); readFile("in.txt"); s = des.StringToRightLength(s); des.CutStringIntoBlocks(s); key = des.CorrectKeyWord(key, s.Length / (2 * des.Blocks.Length)); keyEncode = key; key = des.StringToBinaryFormat(key); for (int j = 0; j < des.quantityOfRounds; j++) { for (int i = 0; i < des.Blocks.Length; i++) { des.Blocks[i] = des.EncodeDES_One_Round(des.Blocks[i], key); } key = des.KeyToNextRound(key); } key = des.KeyToPrevRound(key); keyDecode = des.StringFromBinaryToNormalFormat(key); string result = ""; for (int i = 0; i < des.Blocks.Length; i++) { result += des.Blocks[i]; } writeFile("out1.txt", des.StringFromBinaryToNormalFormat(result)); }; { s = ""; string key = des.StringToBinaryFormat(keyDecode); readFile("out1.txt"); s = des.StringToBinaryFormat(s); des.CutBinaryStringIntoBlocks(s); for (int j = 0; j < des.quantityOfRounds; j++) { for (int i = 0; i < des.Blocks.Length; i++) { des.Blocks[i] = des.DecodeDES_One_Round(des.Blocks[i], key); } key = des.KeyToPrevRound(key); } key = des.KeyToNextRound(key); string results = ""; for (int i = 0; i < des.Blocks.Length; i++) { results += des.Blocks[i]; } writeFile("out2.txt", des.StringFromBinaryToNormalFormat(results)); } sWatch.Stop(); Console.WriteLine("Время выполнения"); Console.WriteLine(sWatch.ElapsedMilliseconds.ToString() + "мс"); break; case 2: sWatch.Start(); tripleDES.Apply3DES(); sWatch.Stop(); Console.WriteLine("Время выполнения"); Console.WriteLine(sWatch.ElapsedMilliseconds.ToString() + "мс"); break; case 3: sWatch.Start(); Console.WriteLine("Зашифрованный текст:"); aes.ToAes256(); aes.FromAes256(aes.ToAes256()); sWatch.Stop(); Console.WriteLine("Время выполнения"); Console.WriteLine(sWatch.ElapsedMilliseconds.ToString() + "мс"); break; case 4: sWatch.Start(); byte[] mmkey = Encoding.Unicode.GetBytes(keyForTwoFish); var mtwM = new TwoFish(mmkey); readFile("in.txt"); decryptedText = Encoding.Unicode.GetBytes(s); encryptedText = mtwM.Encrypt(decryptedText, 0, decryptedText.Count()); writeFile("out1.txt", Encoding.Unicode.GetString(encryptedText)); Console.WriteLine("Зашифрованный текст"); // Console.WriteLine(Encoding.Unicode.GetString(encryptedText)); s = ""; readFile("out1.txt"); encrypted = Encoding.Unicode.GetBytes(Encoding.Unicode.GetString(encryptedText)); decrypted = mtwM.Decrypt(encryptedText, 0, encryptedText.Count()); Console.WriteLine("Расшифрованный текст"); Console.WriteLine(Encoding.Unicode.GetString(decrypted)); sWatch.Stop(); Console.WriteLine("Время выполнения"); Console.WriteLine(sWatch.ElapsedMilliseconds.ToString() + "мс"); break; case 5: sWatch.Start(); s = ""; string keys = "KN@= S]NXGŹHŹNT += ĘźeXvV |$~c"; readFile("in.txt"); serpent.Encrypt("in.txt", Encoding.Unicode.GetBytes(keys), 32, Mode.Standard, EncryptionMode.ECB); serpent.Decrypt("in.serpent", Encoding.Unicode.GetBytes(keys), 32, Mode.Standard, EncryptionMode.ECB); sWatch.Stop(); Console.WriteLine("Время выполнения"); Console.WriteLine(sWatch.ElapsedMilliseconds.ToString() + "мс"); break; default: Console.WriteLine("Введите корректное число"); break; } } }