@Test(expected = IllegalArgumentException.class) public void when_decrypting_and_encrypted_message_and_key_have_different_length_then_throw_IAE(){ encryptor.decrypt(new byte[3], new byte[2]); }
public byte[] decrypt(byte[] encryptedMessage, byte[] randomKey){ if(encryptedMessage.length != randomKey.length){ throw new IllegalArgumentException("message and key have to be of the same length"); } byte[] decodedMessage = new byte[encryptedMessage.length]; for(int i=0;i<encryptedMessage.length; i++){ decodedMessage[i] = (byte) (encryptedMessage[i] ^ randomKey[i]); } return decodedMessage; }
OneTimePadEncryptor { public byte[] decrypt(byte[] encryptedMessage, byte[] randomKey){ if(encryptedMessage.length != randomKey.length){ throw new IllegalArgumentException("message and key have to be of the same length"); } byte[] decodedMessage = new byte[encryptedMessage.length]; for(int i=0;i<encryptedMessage.length; i++){ decodedMessage[i] = (byte) (encryptedMessage[i] ^ randomKey[i]); } return decodedMessage; } }
OneTimePadEncryptor { public byte[] decrypt(byte[] encryptedMessage, byte[] randomKey){ if(encryptedMessage.length != randomKey.length){ throw new IllegalArgumentException("message and key have to be of the same length"); } byte[] decodedMessage = new byte[encryptedMessage.length]; for(int i=0;i<encryptedMessage.length; i++){ decodedMessage[i] = (byte) (encryptedMessage[i] ^ randomKey[i]); } return decodedMessage; }  }
OneTimePadEncryptor { public byte[] decrypt(byte[] encryptedMessage, byte[] randomKey){ if(encryptedMessage.length != randomKey.length){ throw new IllegalArgumentException("message and key have to be of the same length"); } byte[] decodedMessage = new byte[encryptedMessage.length]; for(int i=0;i<encryptedMessage.length; i++){ decodedMessage[i] = (byte) (encryptedMessage[i] ^ randomKey[i]); } return decodedMessage; }  Result encrypt(byte[] message); byte[] decrypt(byte[] encryptedMessage, byte[] randomKey); }
OneTimePadEncryptor { public byte[] decrypt(byte[] encryptedMessage, byte[] randomKey){ if(encryptedMessage.length != randomKey.length){ throw new IllegalArgumentException("message and key have to be of the same length"); } byte[] decodedMessage = new byte[encryptedMessage.length]; for(int i=0;i<encryptedMessage.length; i++){ decodedMessage[i] = (byte) (encryptedMessage[i] ^ randomKey[i]); } return decodedMessage; }  Result encrypt(byte[] message); byte[] decrypt(byte[] encryptedMessage, byte[] randomKey);  }