AES - Bit Distribution
İMike May, S.J., 2002, maymk@slu.edu
| > | restart: |
Following the same pattern we used with Baby DES and DES, we would like to look at the distribution of zeroes and ones from a collection of words encrypted with AES. The digits should behave like independent random variables. First we need to load in the procedures created in AES-Encryption.mws.
| > | read `AES.m`: |
We want a procedure for turning a 32 character hex string into a list of 128 binary digits.
| > | hex1 := "66E94BD4EF8A2C3B884CFA59CA342B2E"; hexStringToBinList := hexString -> [seq(parse(substring( convert(convert(convert(hexString,decimal,hex)+2^128,binary),string), i)),i=2..129)]: hexStringToBinList(hex1); |
We return to our favorite example. For the key we will use the zero word. For our plaintexts, we will use words that are all zeroes except for a single bit that is turned on. In this situation it makes sense to expand the key only once.
The list bitChangeCounter gives us a place to record the number of times each bit is used.
| > | keyHex := intTo128Bits(0); expandedKey := hexKeyExpander(hexkey): bitChangeCounter := [seq(0,i=1..128)]: testLine2 := intVal -> encryptAESExpanded(intTo128Bits(2^(intVal-1)),expandedKey): |
We are ready to count the number of times a bit is used in each of the first 30 test words.
| > | for i from 1 to 30 do bitChangeCounter := zip(`+`,bitChangeCounter, hexStringToBinList(testLine2(i))): end do: bitChangeCounter; |
| > | stats[transform,tally](bitChangeCounter); evalf(stats[describe, mean](bitChangeCounter)); evalf(stats[describe, standarddeviation](bitChangeCounter)); |
The expected mean is 30*.5 = 15. The expected standard deviation is sqrt(30*.5*.5)=2.7386.
The behavior looks like what we expect from a random distribution of bits.
| > |
| > |