Fix payload padding to avoid loop #6
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey,
Thanks for the awesome challenge (and the solving script)! I would like to make a friendly contribution :)
In order to avoid padding for a single base64 encoding, we need the length l of our initial message to be a multiple of 3, as three 8-bit characters are encoded as exactly four 6-bit/base64 characters.
The length of the resulting message will be l × 4 / 3, since three characters are encoded into four.
len(x) = l × 4 / 3
len(xx) = l × 4 / 3 × 4 / 3
len(xxx) = l × 4 / 3 × 4 / 3 × 4 / 3
For xxx to not contain padding, we need len(xx) to be a multiple of 3; same reasoning for len(xx), for which you need len(x) to be a multiple of 3, and len(x) for which you need l to be a multiple of 3.
Since 3 and 4 are coprime, we can sort of remove the 4 from the equations for our reasoning.
Hence, we need:
l % 3 == 0 && len(x) % 3 == 0 && len(xx) % 3 == 0
<=> l % 3 == 0 && l / 3 % 3 == 0 && l / 3 / 3 % 3 == 0
<=> l % 3^3 == 0
<=> l % 27 == 0
Sorry for the long-winded (possibly unneeded?) explanation!