public void Decrypt_Plaintext() { // Get the bytes of the string "Key". This will be the decryption key // that we use. byte[] key = Encoding.ASCII.GetBytes("Key"); byte[] data = (byte[])CIPHER_PLAINTEXT.Clone(); // Decrypt the cipher using the key ARC4.Apply(data, key); // Decode the decrypted array string decoded = Encoding.ASCII.GetString(data); // Validate the decoded string Assert.AreEqual(decoded, "Plaintext"); }
public void Encrypt_Plaintext() { // Get the bytes of the string "Plaintext". This will be the data // that we are encoding. byte[] data = Encoding.ASCII.GetBytes("Plaintext"); // Get the bytes of the string "Key". This will be the encryption key // that we use. byte[] key = Encoding.ASCII.GetBytes("Key"); // Encrypt the data using the key ARC4.Apply(data, key); // Validate that the encrypted data is the same as the cipher data Assert.IsTrue(data.SequenceEqual(CIPHER_PLAINTEXT)); }
public void Decrypt_AttackAtDawn() { // Get the bytes of the string "Key". This will be the decryption key // that we use. byte[] key = Encoding.ASCII.GetBytes("Secret"); byte[] data = (byte[])CIPHER_ATTACKATDAWN.Clone(); // Decrypt the cipher using the key ARC4.Apply(data, key); // Decode the decrypted array string decoded = Encoding.ASCII.GetString(data); // Validate the decoded string Assert.AreEqual(decoded, "Attack at dawn"); }
public void Encrypt_AttactAtDawn() { // Get the bytes of the string "Attack at dawn". This will be the data // that we are encoding. byte[] data = Encoding.ASCII.GetBytes("Attack at dawn"); // Get the bytes of the string "Secret". This will be the encryption key // that we use. byte[] key = Encoding.ASCII.GetBytes("Secret"); // Encrypt the data using the key ARC4.Apply(data, key); // Validate that the encrypted data is the same as the cipher data Assert.IsTrue(data.SequenceEqual(CIPHER_ATTACKATDAWN)); }
public void Encrypt_Pedia() { // Get the bytes of the string "pedia". This will be the data // that we are encoding. byte[] data = Encoding.ASCII.GetBytes("pedia"); // Get the bytes of the string "Wiki". This will be the encryption key // that we use. byte[] key = Encoding.ASCII.GetBytes("Wiki"); // Encrypt the data using the key ARC4.Apply(data, key); // Validate that the encrypted data is the same as the cipher data Assert.IsTrue(data.SequenceEqual(CIPHER_PEDIA)); }
public void Encrypt_PartOfPlaintext() { // Get the bytes of the string "Plaintext". This will be the data // that we are encoding. byte[] data = Encoding.ASCII.GetBytes("Plaintext"); // Get the bytes of the string "Key". This will be the encryption key // that we use. byte[] key = Encoding.ASCII.GetBytes("Key"); // Encrypt only part of the data using the key ARC4.Apply(data, key, 0, 2); ARC4.Apply(data, key, 0, 2); Assert.AreEqual(Encoding.ASCII.GetString(data, 0, 2), "Pl"); // Encrypt only part of the data using the key ARC4.Apply(data, key, 2, 3); ARC4.Apply(data, key, 2, 3); Assert.AreEqual(Encoding.ASCII.GetString(data, 2, 3), "ain"); }