Saturday, December 24, 2016

[hknbgvds] Append B

Take a word or message (without spaces) and interpret it as value in base 26, encoded little endian: a=0, b=1,... z=25.  Messages ending in an arbitrary number of a's cannot be distinguished from each other, analogous to invisible leading zeroes: 7 and 007 are the same big-endian decimal value but have different meanings.

Standard trick to solve this problem (e.g., seen for binary messages for MD5 and SHA-1): append a "b" to the end of the message (most significant digit), then convert the little-endian message to a value.  When decoding a value, strip the trailing b.

Other simple ideas: permit spaces in the message and use space=0, a=1,... z=26.  Trailing spaces get lost, which might be fine.  If big-endian, then leading spaces get lost.

Having converted a message to a value, proceed with, e.g., encryption.  Computers can compute radix conversion very quickly.

Converting a value to an output encoding in some base is easy.  If leading zeroes are again relevant, convert first to binary then to the target base.

Inspired by the awkwardness of needing base 32 for a simple cipher .  This encoding may grow the message by a letter or two, so not quite fitting in the original template.  (Of course, one would never keep the original message template for real encryption.  Use some other template.)

No comments :