Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-161

CTR Counter Block

Problem

Build a 16-byte counter block for CTR mode: an 8-byte nonce followed by the counter encoded as 8 bytes big-endian. nonce is a list of 8 byte values and counter is a nonnegative integer.

Hint

Big-endian means the most significant byte comes right after the nonce.

Test cases

case 1
in: [[0,0,0,0,0,0,0,0],1]
expected: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
case 2
in: [[1,2,3,4,5,6,7,8],256]
expected: [1,2,3,4,5,6,7,8,0,0,0,0,0,0,1,0]
case 3
in: [[0,0,0,0,0,0,0,0],65536]
expected: [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0]
case 4
in: [[9,9,9,9,9,9,9,9],0]
expected: [9,9,9,9,9,9,9,9,0,0,0,0,0,0,0,0]
Starter codePython
def ctr_counter_block(nonce, counter):
    # Your code here
    pass

4 test cases · run your code against them in the editor