summaryrefslogtreecommitdiff
path: root/python/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/helpers.py')
-rw-r--r--python/helpers.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/python/helpers.py b/python/helpers.py
index b02bea4..07affa9 100644
--- a/python/helpers.py
+++ b/python/helpers.py
@@ -3,20 +3,23 @@ from lilliput_tbc import LilliputTBCEnc
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
+ vector = list(array)
+
+ blocks_nb = len(vector)//BLOCK_BYTES
+
+ block_starts = (
+ i*BLOCK_BYTES for i in range(blocks_nb)
+ )
+
+ matrix = [
+ vector[start:start+BLOCK_BYTES] for start in block_starts
+ ]
- matrix = [[0] * BLOCK_BYTES for block in range(0, number_blocks - pad)]
- if pad == 1:
- matrix.append([0] * (length % BLOCK_BYTES))
+ padding_len = len(vector)%BLOCK_BYTES
- for byte in range(0, length):
- matrix[int(byte / BLOCK_BYTES)][byte % BLOCK_BYTES] = array[byte]
+ if padding_len > 0:
+ padding = vector[-padding_len:]
+ matrix.append(padding)
return matrix