Formula to convert *any* word into a number?

rrrr0000

New Member
Joined
Sep 5, 2021
Messages
6
Office Version
  1. 2010
Platform
  1. Windows
Hello. I have searched up and down and have not found a suitable solution here. But I am basically looking for a formula to turn ANY word into a number. But I do not have a list of specific words. We are talking any word in the English language. o_O As in, take any sentence you can find, and convert it to number strings with SOME kind of consistent logic applied.

Maybe something like assigning a value to each letter and then taking the sum value of all the letters to create one number per word? Or just creating a string where a numerical value for each letter is just appeneded to a string? Like if a=1 and t=21 then the word "at" could be =22 (1+21), or =121 (1&21)... maybe something like that?

I imagine I could split each word into a separate letter in each cell, then assign a value for each letter in each cell, but it could end up being like 10,000 columns... and then I would to recombine them and maintain the spacing/separation somehow. Not sure if this makes sense to anyone. But some extra brainpower would be appreciated. I don't have any defined parameters for method or preferred values.

This is just step one for a fun personal project. Thanks in advance for your time!

For example just for illustration - the numbers here are meaningless and not specific to any logic - just to give you an idea:

Thequickbrownfoxjumpsoverthelazydog
8334344553177254546464541426466568932468905751353235
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
UPDATE: No need to respond, I figured out a solution that will work.
 
Upvote 0
Use a hashing function (which I found here)

VBA Code:
Function ConvertAnyWord2Number(Word As String) As Long
    Dim S As String, Ch As String, N As Long, I As Long
   
    S = Base64Sha1(Word)
    For I = 1 To Len(S)
        Ch = Mid(S, I, 1)
        N = N + asc(Ch)
    Next I
    ConvertAnyWord2Number = N
End Function

Private Function Base64Sha1(inputText As String, Optional secretKey = "") As String
   
    Dim asc As Object
    Dim enc As Object
    Dim textToHash() As Byte
    Dim SharedSecretKey() As Byte
    Dim bytes() As Byte
   
    If secretKey = "" Then secretKey = inputText
   
    Set asc = CreateObject("System.Text.UTF8Encoding")
    Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
   
    textToHash = asc.GetBytes_4(inputText)
    SharedSecretKey = asc.GetBytes_4(secretKey)
    enc.Key = SharedSecretKey
   
    bytes = enc.ComputeHash_2((textToHash))
    Base64Sha1 = EncodeBase64(bytes)
   
End Function

Private Function EncodeBase64(arrData() As Byte) As String
   
    Dim objXML As Object
    Dim objNode As Object
   
    Set objXML = CreateObject("MSXML2.DOMDocument")
    Set objNode = objXML.createElement("b64")
   
    objNode.DataType = "bin.base64"
    objNode.nodeTypedValue = arrData
    EncodeBase64 = objNode.Text
End Function
 
Upvote 0
Solution
thank you rlv01. I ended up using another solution -- just a riduclously long nested SUBSTITUTE formula with every letter of the alphabet mapped to a number and somehow managed to get the correct amount of open and closed parenthesis (y)
 
Upvote 0
UPDATE: No need to respond, I figured out a solution that will work.
Glad you figured out a solution. I'll leave you with a final thought that only applies if the reason you are doing this involves security (i.e. passwords or access authorizations): homegrown hashing methods have proven time and again to be much easier to crack that their authors ever assume. Don't rely on them for any situation were the security required is more than trivial.
 
Upvote 0
Ah... thanks. No it's for an art project. Turning words into shapes, that sort of thing.

But your suggestion does bring up an idea. Maybe just input sentences into a security key generator. That could work too!
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top