开发者

Y = base64(X) where X is integer - is Y alphanumeric?

Additional details:

Please explain your answer :)

(This might be better in the Math site, but figured it involves programming functions)


The picture from the german Wikipedia article is very helpful:

Y = base64(X) where X is integer - is Y alphanumeric?

You see that 6 consecutive bits from the original bytes generate a Base64 value. To generate + or / (codes 62 and 63), you'd need the bitstrings 111110 and 111111, so at least 5 consecutive bits set.

However, look at the ASCII codes for 0...9:

00110000
00110001
00110010
00110011
00110100
00110101
00110110
00110111
00111000
00111001

No matter how you concatenate six of those, there won't be more than 3 consecutive bits set. So it's not possible to generate a Base64 string that contains + or / this way, Y will always be alphanumeric.

EDIT: In fact, you can even rule other Base64 values out like 000010 (C), so this leads to nice follow-up questions/puzzles like "How many of the 64 values are possible at all?".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜