Developers.Hash.Text
Text encoding and URI prefixes
I'm trying to write code that will generate all the text encoding and URI prefix possibilities. The sections here are added from the bottom of the HashData function.
If a method gives an option to include a URI prefix, I've indicated true to see what it looks like.
<source lang="c"> // Express the values as text using base 16 and base 32 CString md4base16 = CMD5::HashToString(&md4value, true); // Borrowing MD5's static method CString md4base32 = ""; CString md5base16 = CMD5::HashToString(&md5value, true); CString md5base32 = ""; CString sha1base16 = CSHA::HashToHexString(&sha1value, true); CString sha1base32 = CSHA::HashToString(&sha1value, true); CString tigerbase16 = ""; CString tigerbase32 = tiger.RootToString(); CString donkeybase16 = CED2K::HashToString(&md4value, true); CString donkeybase32 = "";
// Access the memory of the hash value directly to do the same thing CString md4base16a = tobase16byte*)(&md4value), sizeof(md4value; CString md4base32a = tobase32byte*)(&md4value), sizeof(md4value; CString md5base16a = tobase16byte*)(&md5value), sizeof(md5value; CString md5base32a = tobase32byte*)(&md5value), sizeof(md5value; CString sha1base16a = tobase16byte*)(&sha1value), sizeof(sha1value; CString sha1base32a = tobase32byte*)(&sha1value), sizeof(sha1value; CString tigerbase16a = tobase16byte*)(&tigervalue), sizeof(tigervalue; CString tigerbase32a = tobase32byte*)(&tigervalue), sizeof(tigervalue; CString donkeybase16a = tobase16byte*)(&donkeyvalue), sizeof(donkeyvalue; CString donkeybase32a = tobase32byte*)(&donkeyvalue), sizeof(donkeyvalue; </source>
I don't know how to get MD4 and MD5 in base 32, tiger in base 16, and donkey in base 32. Here is the output form hashing the 5 bytes of the ASCII text hello.
<source lang="c"> md4base16a "866437cb7a794bce2b727acc0362ee27" md4base16 "md5:866437cb7a794bce2b727acc0362ee27"
md4base32a "qzsdps32pff44k3splgagyxoe4" md4base32
md5base16a "5d41402abc4b2a76b9719d911017c592" md5base16 "md5:5d41402abc4b2a76b9719d911017c592"
md5base32a "lvauakv4jmvhnolrtwiraf6fsi" md5base32
sha1base16a "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" sha1base16 "urn:sha1:AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D"
sha1base32a "vl2mmho4yxukfwv63yhtwsbm3gxksq2n" sha1base32 "urn:sha1:VL2MMHO4YXUKFWV63YHTWSBM3GXKSQ2N"
tigerbase16a "398ef4d84353cbe0f831a64418f3012a5419494727186eed" tigerbase16
tigerbase32a "hghpjwcdkpf6b6bruzcbr4ybfjkbsskhe4mg53i" tigerbase32 "HGHPJWCDKPF6B6BRUZCBR4YBFJKBSSKHE4MG53I"
donkeybase16a "866437cb7a794bce2b727acc0362ee27 donkeybase16 "urn:ed2khash:866437cb7a794bce2b727acc0362ee27"
donkeybase32a "qzsdps32pff44k3splgagyxoe4" donkeybase32 </source>
camper's code
Now, the same function working in the pre-alpha 2.3 with camper's code.
<source lang="c"> // Express the values as text using base 16 and base 32 CString md4base16 = ""; CString md4base32 = ""; CString md5base16 = md5value.toString(); CString md5base32 = ""; CString sha1base16 = ""; CString sha1base32 = sha1value.toString(); CString tigerbase16 = ""; CString tigerbase32 = tigervalue.toString(); CString donkeybase16 = donkeyvalue.toString(); CString donkeybase32 = "";
// Try out the toUrn methods on the hash value objects CString md4u = ""; CString md5u = md5value.toUrn(); CString sha1u = sha1value.toUrn(); CString tigeru = tigervalue.toUrn(); CString donkeyu = donkeyvalue.toUrn();
// Access the memory of the hash value directly to do the same thing CString md4base16a = tobase16byte*)(&md4value), sizeof(md4value; CString md4base32a = tobase32byte*)(&md4value), sizeof(md4value; CString md5base16a = tobase16(&md5value[0], Hashes::Md5Hash::byteCount); CString md5base32a = tobase32(&md5value[0], Hashes::Md5Hash::byteCount); CString sha1base16a = tobase16(&sha1value[0], Hashes::Sha1Hash::byteCount); CString sha1base32a = tobase32(&sha1value[0], Hashes::Sha1Hash::byteCount); CString tigerbase16a = tobase16(&tigervalue[0], Hashes::TigerHash::byteCount); CString tigerbase32a = tobase32(&tigervalue[0], Hashes::TigerHash::byteCount); CString donkeybase16a = tobase16(&donkeyvalue[0], Hashes::Ed2kHash::byteCount); CString donkeybase32a = tobase32(&donkeyvalue[0], Hashes::Ed2kHash::byteCount); </source>
And, the results.
<source lang="c"> md4u
md4base16a "866437cb7a794bce2b727acc0362ee27" md4base16
md4base32a "qzsdps32pff44k3splgagyxoe4" md4base32
md5base16a "5d41402abc4b2a76b9719d911017c592" md5base16 "5d41402abc4b2a76b9719d911017c592" md5u "urn:md5:5d41402abc4b2a76b9719d911017c592"
md5base32a "lvauakv4jmvhnolrtwiraf6fsi" md5base32
sha1base16a "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" sha1base16
sha1base32a "vl2mmho4yxukfwv63yhtwsbm3gxksq2n" sha1base32 "VL2MMHO4YXUKFWV63YHTWSBM3GXKSQ2N" sha1u "urn:sha1:VL2MMHO4YXUKFWV63YHTWSBM3GXKSQ2N"
tigerbase16a "398ef4d84353cbe0f831a64418f3012a5419494727186eed" tigerbase16
tigerbase32a "hghpjwcdkpf6b6bruzcbr4ybfjkbsskhe4mg53i" tigerbase32 "HGHPJWCDKPF6B6BRUZCBR4YBFJKBSSKHE4MG53I" tigeru "urn:tree:tiger/:HGHPJWCDKPF6B6BRUZCBR4YBFJKBSSKHE4MG53I"
donkeybase16a "866437cb7a794bce2b727acc0362ee27" donkeybase16 "866437cb7a794bce2b727acc0362ee27" donkeyu "urn:ed2khash:866437cb7a794bce2b727acc0362ee27"
donkeybase32a "qzsdps32pff44k3splgagyxoe4" donkeybase32 </source>
Questions
- Is there a way to get the missing strings in both Shareaza 2.0 and camper's code?
- Wouldn't a better design that would be easier to use and program just be to have functions that turn data to encoded text, and the + operator stick on "urn:sha1:" or whatever prefix you want?