1

As the title states:

byte[] encrypted = CryptUtils.encrypt(data, key);

System.out.println(encrypted.length);
System.out.println(new BigInteger(1, encrypted));
System.out.println(Hex.encodeHexString(encrypted));
System.out.println(Base64.encodeBase64URLSafeString(encrypted));

outputs:

256
7168009243437822369854296216469732927594459719440755727503201192530003257397163143550783701334794173832880442110749731484646074400131932467256279320823407781569648004807653365193397061746088055905459344661520563977412309879548615096199872078298147648980941323616588222390445048851049622860590706553997636199882023404309651714685195366372945729024803306545341378698784529621539295122723246344789485664483371790124134351446837929993273793110653964164218755076959002468887573158308128829469244818441239599777150957470054497913346467414443384627016093340619366633629652523989548335430064353047141257059570514456595059522
38c815051cbe7d70b4498cb0899626bfbb42d973025f73ccb7bac5b927a2e5454fd1fff95a0457450039e19c545b88fb5065569e0f60d787d90e7f7701d8db39b2fbcf7500aa3a94b6f0a893a8892b55e0bedeb1cec0ab6adb4bffecd758ccd675ea51d3f090d266adca9e5a72ab0448426585e5ea306eea7f3607cd952a1a7b4a07bceba063ef04fa462c92ebffc65a35850aa37a31a405e98531e52631577e944bc0f22fcae33c9c93d6ff5d384e066a3c8b620abb5019aeeec8143acf74018a7eff33744ac94a6ac1f736a74868986759b24fb66a0274665f70ac5a27e1ab0e983931f3173dcb61610700b743de6a1e85653a2424bba671aa39debc3ed342
OMgVBRy-fXC0SYywiZYmv7tC2XMCX3PMt7rFuSei5UVP0f_5WgRXRQA54ZxUW4j7UGVWng9g14fZDn93AdjbObL7z3UAqjqUtvCok6iJK1Xgvt6xzsCrattL_-zXWMzWdepR0_CQ0matyp5acqsESEJlheXqMG7qfzYHzZUqGntKB7zroGPvBPpGLJLr_8ZaNYUKo3oxpAXphTHlJjFXfpRLwPIvyuM8nJPW_104TgZqPItiCrtQGa7uyBQ6z3QBin7_M3RKyUpqwfc2p0homGdZsk-2agJ0Zl9wrFon4asOmDkx8xc9y2FhBwC3Q95qHoVlOiQku6ZxqjnevD7TQg

Is there a shorter intellegible form than base64?

What's the shortest?

Michele Mariotti
  • 7,372
  • 5
  • 41
  • 73

2 Answers2

1

Shortest would need some clarification. But if we're talking about printing it (to the console), we imply human readable characters.

Human readable character set that is displayable on all terminals is basically the English alphabet (lower and upper case letters), digits plus some signs, which altogether are less than 128. The biggest power of 2 that is less than 128 is 64 which is the element count of the Base64 encoding.

Basically you want to represent bytes with a character set whose size is a power of 2 (because a byte is an integer number of bits: 8) so the conversion between the bytes and the indices of the displayable characters will be easy and fast.

Using a larger charset than 64 would have to use characters which might not be displayable on all terminals, or could not be used in URLs or file names etc.

So Base64 is your best bet if you want it to be compact, readable, efficient and portable at the same time. You might consider Base128 if you're willing to sacrafice some portability to the gain of slightly shorter representation.

Note that if you just want it to work on specific terminals/applications which support certain ranges of unicode characters, you might even display 1 byte as one character in which case the text (character) length would be the same as the byte length, or even more, 1 unicode character could represent 2 bytes.

icza
  • 389,944
  • 63
  • 907
  • 827
1

The shortest I've found is basE91, which you can find at http://base91.sourceforge.net/

gknicker
  • 5,509
  • 2
  • 25
  • 41
  • I'd prefer a power-of-two-sized codec, but your linked answer explains and clarifies perfectly the problem :) – Michele Mariotti Jan 07 '15 at 09:32
  • base91 has the advantage that you can use a lookup table for encoding/decoding, so the performance lost will be much smaller than encodings that have to use multiplications/divisions for conversion like base85 – phuclv Apr 12 '18 at 11:19