基础36表示摘要

Sha*_*rog 10 ruby hash digest base36

我希望能够获取任意字符串,通过散列函数(如MD5)运行它,然后在base-36中解释生成的摘要.

我知道在Ruby中已经存在一个Digest库,但据我所知,我无法得到摘要的原始字节; 该to_s函数被映射到hexdigest,当然,它是base-16.

Sam*_*rbi 21

Fixnum#to_s接受一个base作为参数.字符串#to_i也是如此.因此,您可以从base-16字符串转换为int,然后转换为36字符串:

i = hexstring.to_i(16)
base_36 = i.to_s(36)
Run Code Online (Sandbox Code Playgroud)