/** * Encrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void encryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex+4); xl ^= P[0]; for (int i = 1; i < ROUNDS; i += 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i + 1]; } xr ^= P[ROUNDS + 1]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex + 4); }
/** * Decrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void decryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex + 4); xl ^= P[ROUNDS + 1]; for (int i = ROUNDS; i > 0 ; i -= 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i - 1]; } xr ^= P[0]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex+4); }
/** * Encrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void encryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex+4); xl ^= P[0]; for (int i = 1; i < ROUNDS; i += 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i + 1]; } xr ^= P[ROUNDS + 1]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex + 4); }
/** * Decrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void decryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex + 4); xl ^= P[ROUNDS + 1]; for (int i = ROUNDS; i > 0 ; i -= 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i - 1]; } xr ^= P[0]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex+4); }