You are misleading the presentation with content.
sha1 is 160 bits of binary data. You can just as easily imagine it with:
hex: 0xf1d2d2f924e986ac86fdf7b36c94bcdf32beec15 decimal: 1380568310619656533693587816107765069100751973397 binary: 1111000111010010110100101111100100100100111010011000011010101100100001101111110111110111101100110110110010010100101111001101111100110010101111101110110000010101 base 62: xufK3qj2bZgDrLA0XN0cLv1jZXc
There is nothing magical about hexadecimal. This is a very common mechanism for displaying content, which is easily divided into 4-bit boundaries.
The base 62 output is generated using this small amount of ruby:
#!/usr/bin/ruby def chars_from_hex(s) c = s % 62 s = s / 62 if ( s > 0 ) chars_from_hex(s) end if (c < 10) print c elsif (c < 36) print "abcdefghijklmnopqrstuvwxyz"[c-11].chr() elsif (c < 62) print "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[c-37].chr() else puts "error c", c end end chars_from_hex(0xf1d2d2f924e986ac86fdf7b36c94bcdf32beec15)
It uses the standard idiom to convert from one database to another and treats 0-9 as 0-9, az as 10 -35, az as 36-61. This can be trivially expanded to support more digits by including, for example, !@ #$%^&*()-_=+\|[]{},.<>/?;:'"~` If this is so necessary. (Or any of the huge array of Unicode codepoints .)
@ yes123 asked a question about representing the ascii hash function on purpose, so here is the result of interpreting the 160-bit hash directly as ascii:
ñÒÒù$é¬ý÷³l¼ß2¾ì
This is not like that because:
- ascii does not have a good printable representation for byte values less than 32
- ascii itself cannot represent byte values greater than 127, between 127 and 255 is interpreted in accordance with iso-8859-01 or another character encoding scheme
This basic conversion can be practically useful; The Base64 method uses 64 (instead of 62) characters to represent 6 bits at a time; he needs two more characters for the "numbers" and a character to fill. UUEncoding has chosen a different set of "numbers". And the drive colleague had a problem that was easily solved by changing the base of input numbers to output numbers .
source share