Create hash from string - anything in Coda like Excel CODE formula?

I want to create a short code ID for for each of my tasks by hashing the task name ie “Take out the garbage” == XDYP or “Clean my room” == HGCP. I was inspired by the second answer to this Stack Overflow:

which is essential to use this formula:

=MOD(MOD(MOD(MOD(MOD(IF(LEN(Z2)>=1,CODE(MID(Z2,1,1))+10,31),1009)*IF(LEN(Z2)>=3,CODE(MID(Z2,3,1))+10,41),1009)*IF(LEN(Z2)>=5,CODE(MID(Z2,5,1))+10,59),1009)*IF(LEN(Z2)>=7,CODE(MID(Z2,7,1))+10,26),1009)*IF(LEN(Z2)>=9,CODE(MID(Z2,9,1))+10,53),1009)

Its a clever way to convert each character into a number and then perform some maths. It doesn’t need to be encryption grade because a collision is no big deal for my tasks.

The key to making it work above is the CODE function in excel which gives you the unicode numeric value of the character, kind of like the inverse of the character() function in coda.

Any ideas on how to do this in Coda?

For the last part: you can create a convertion table and reference it in the formula.

@Asaf_Dafna yes I was hoping to avoid building a whole complex system / table and hoping a couple of formulas strung together would do it / someone had already thought of how to create the hash.

Even with the table, how do you iterate through a string and pull out each letter to look up? I think it would have to be a concoction of formulamap(), length(), and left()?

You can iterate over chars with
String.Split("").FormulaMap(...)

Not super efficient since it makes a list, but elegant.

Use the Crypto pack (MD5, SHA1, SHA256 and SHA512 available) for free :slight_smile:
https://coda.io/packs/crypto-1069

2 Likes