

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Block Ciphers
incomplete
2: Block vs. Stream
incomplete
3: Block Sizes
incomplete
4: Chunks Review
incomplete
5: Key Schedules
incomplete
6: Key Schedule Review
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Block ciphers use fixed-size blocks and fixed-size keys. However, just because the blocks are fixed-size doesn't mean the message must be a fixed size as well. Block ciphers can operate on messages of any length, and the key doesn't even need to be the same length as the message or the block.
For example:
Messages in a block cipher are broken up into blocks, and each block is encrypted separately.
For example, let's say we are using a cipher that requires 256-bit blocks. We have a message of 650 bits that we want to encrypt. The algorithm would break that message up into three blocks:
block1 = first 256 bits
block2 = next 256 bits
block3 = last 138 bits
The last block is then padded with extra garbage bits so that it also has 256 bits of data. That padding is stripped off when the message is decrypted.
While robust cryptography libraries take care of block padding for us, it's important to understand how it works. As part of employee onboarding at Passly, we require our cryptography engineers to write a padding function from scratch so they can understand how it works.
Complete the padWithZeros function. It takes a message (block) as a []byte and a desired output size. It should increase the size of block by adding zero-value-bytes until it has a length of desiredSize. Return the new byte slice.