### Question:
CachingSha2Authenticator { public static byte[] encode(byte[] password, byte[] nonce) { MessageDigest messageDigest; try { messageDigest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } byte[] passwordHash1 = messageDigest.digest(password); messageDigest.reset(); byte[] passwordHash2 = messageDigest.digest(passwordHash1); messageDigest.reset(); messageDigest.update(passwordHash2); byte[] passwordDigest = messageDigest.digest(nonce); for (int i = 0; i < passwordHash1.length; i++) { passwordHash1[i] = (byte) (passwordHash1[i] ^ passwordDigest[i]); } return passwordHash1; }  static byte[] encode(byte[] password, byte[] nonce);  }### Answer:
@Test public void testEncode() { scrambledPasswordHexStr = "83ad20dc9b0c61f959fb93f451a42fc2d15ab811b882d667fe8f0fcd0a8acaeb"; nonce = new byte[]{ 0x36, 0x47, 0x48, 0x05, 0x03, 0x6c, 0x6e, 0x60, 0x54, 0x73, 0x50, 0x61, 0x2b, 0x1b, 0x12, 0x04, 0x6e, 0x5a, 0x79, 0x60 }; Assert.assertEquals(scrambledPasswordHexStr, StringUtil.toHexString(CachingSha2Authenticator.encode(PASSWORD, nonce))); }
@Test public void testEncode2() { scrambledPasswordHexStr = "3d58c194ffdaf1f80a6c5ef67700608b07f9a29d37c9e2307aaf690c6e5526ab"; nonce = new byte[]{ 0x6f, 0x2d, 0x5c, 0x6d, 0x66, 0x04, 0x10, 0x70, 0x2b, 0x71, 0x37, 0x76, 0x63, 0x39, 0x2a, 0x02, 0x6d, 0x4a, 0x25, 0x47 }; Assert.assertEquals(scrambledPasswordHexStr, StringUtil.toHexString(CachingSha2Authenticator.encode(PASSWORD, nonce))); }