Pergunta

I have some 16 character hex strings like this:

B5A43BC5BDCEEFC6
2C7C27F05A488897
1514F4EC47C2EBF6
D91ED66BC999EB64

I want to shorten them and have the shortened string only contain upper case letters.

DeflateStream and GZipStream just increase the length.

Anyone can help me shorten these 16 characters hex string to 6 characters or fewer?

Alternatively, shortening a 32 character hex string to 12 characters or fewer is okay.

Foi útil?

Solução 2

You can convert hexadecimal number to a higher base like sexagesimal:

Quickest way to convert a base 10 number to any base in .NET?

Outras dicas

Unless there is some redundancy in your 16 hexadecimal character input, what you are asking is mathematically impossible. You can prove this by examining the entropy of your inputs.

  • You have 16 hexadecimal characters.

16^16 = 18446744073709551616 ≈ 1.84x10^19 possible values.

  • You want the string to be 6 upper (or lower - the maths is the same) case characters or fewer. In English (I assume you want English) there are 26 uppercase characters.

26^6 = 308915776 ≈ 3.09x10^8 possible values.


  • To guarantee that you can represent every one of your 16 hexadecimal characters, you need 14 upper (or lower) case letters.

  • 13 characters isn't enough:

26^13 = 2481152873203736575 ≈ 2.48x10^18 possible values.

  • 14 characters will suffice:

26^14 = 64509974703297150976 ≈ 6.45x10^19 possible values.


  • The only way you could possibly do it (assuming no redundancy) in six (or fewer) characters is to have some base where each character has 1626 possible values.

1626^6 = 18480905552168525376 ≈ 1.849x10^19 possible values.


Shortening 32 hexadecimal characters to 12 or fewer upper (or lower) case characters is impossible by the same logic. Without redundancy, you can't guarantee that you can shorten any arbitrary 16 (or 32) hexadecimal characters into 6 (or 12) upper (or lower) case characters.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top