blob: 34949a4f564dde8c54ed647f93c3a52331a99ad7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
from constants import BLOCK_BYTES
def ArrayToBlockbytesMatrix(array) :
length = len(array)
pad = 0
if(length % BLOCK_BYTES == 0) :
number_blocks = int(length / BLOCK_BYTES)
else :
number_blocks = int((length + (BLOCK_BYTES - (length % BLOCK_BYTES))) / BLOCK_BYTES)
pad = 1
matrix = [[0] * BLOCK_BYTES for block in range(0, number_blocks - pad)]
if(pad == 1) :
matrix.append([0] * (length % BLOCK_BYTES))
for byte in range(0, length) :
matrix[int(byte / BLOCK_BYTES)][byte % BLOCK_BYTES] = array[byte]
return matrix
def BlockbytesMatrixToBytes(matrix):
return bytes(byte for block in matrix for byte in block)
|