I can't find a useful answer for this in relation to Java here or on the web in general. The problem is seemingly simple - I need a way of counting the number of bits contained in a byte array of arbitrary size. The byte array can hold hex, decimal or binary values.
I'm sure this is one of those questions that will have me kicking myself when I see an answer, but it's proving extremely frustrating. The method should look something like:
public int bitsInByteArray(byte[] b) {
return - sum of bit count (ie the sum total bits, not the sum of their values)
of each byte in b
}
Any direction or advice would be immensely appreciated.
EDIT - Apologies guys, I didn't word this right at all. I'm doing a crypto assignment, and have been asked to "encrypt a single block containing 64 zero bits using AES with the key k" Now, I created byte[] zeroBlockAes = {0x0,0x0...0x0} until it contains 64 zero elements. The problem is, this is a 512 bits surely? So should I just put eight zero values in?
When I do this, my encrypted output is -75 111 69 107 -18 88 51 89 68 -123 -49 18 -26 -109 94 21
And when I decrypt again I get my original eight zeros. Is this normal in AES or am I possibly doing something wrong, I thought block ciphers produced the same size input / output for both encryption and decryption.
1 byte = 8 bits
? Then ask it directly, rather than framing a random question out of it. – Rohit Jain Oct 26 '12 at 20:18