[Cryptography Team] interleaving indexing has me scrambled
Robert Withers
robert.w.withers at gmail.com
Thu Dec 17 03:23:12 UTC 2015
In particular the tempIndex of the second scan goes out of range and I
scratching my head. If anyone actually wants to look at how this method
works and can help, awesome! :)
best,
robert
---
interleave: symbols blockCount: blockCount
| symbolsPerChunk table interleaved interleavedBlock fourChunk
symbolsPerBlock |
((symbols size \\ 4) > 0) ifTrue: [self error: 'interleaving bytes size
not a multiple of 4'].
symbolsPerChunk := symbols size // blockCount.
symbolsPerBlock := symbols size // (blockCount // 4).
table := OrderedCollection new: 4 withAll: 0.
table at: 1 put: (ByteArray new: symbolsPerChunk withAll: 0).
table at: 2 put: (ByteArray new: symbolsPerChunk withAll: 0).
table at: 3 put: (ByteArray new: symbolsPerChunk withAll: 0).
table at: 4 put: (ByteArray new: symbolsPerChunk withAll: 0).
interleavedBlock := ByteArray new: (symbols size / blockCount) withAll: 0.
interleaved := ByteArray new: (symbols size + 1) withAll: 0.
interleaved at: 1 put: blockCount.
0 to: blockCount - 1 do: [ :blockIndex |
| end start |
start := blockIndex * symbolsPerBlock + 1.
end := (blockIndex + 1) * symbolsPerBlock.
fourChunk := symbols copyFrom: start to: end.
"first scan: bytes to populate the table"
0 to: 3 do: [ :chunkIndex |
| chunk slice symbol |
chunk := fourChunk copyFrom: (chunkIndex * symbolsPerChunk + 1) to:
((chunkIndex + 1) * symbolsPerChunk).
1 to: symbolsPerChunk do: [ :index |
slice := table at: (chunkIndex + 1).
symbol := chunk at: index.
slice at: index put: symbol]].
"second scan: table to populate the interleaved bytes"
1 to: symbolsPerChunk do: [ :index |
0 to: 3 do: [ :chunkIndex |
| localIndex offset tempIndex symbol |
offset := symbolsPerBlock * blockIndex.
tempIndex := index * 4 + chunkIndex - 3.
localIndex := offset + tempIndex.
symbol := (table at: (chunkIndex + 1)) at: index.
interleavedBlock at: localIndex put: symbol]].
start := symbols size / blockCount * blockIndex + 1.
end := symbols size / blockCount * blockIndex + interleavedBlock size.
interleaved replaceFrom: (start + 1) to: (end + 1) with:
interleavedBlock startingAt: 1].
^ interleaved
More information about the Cryptography
mailing list