Using ColdFusion to Find a Mysterious String That When Hashed Returns Itself

After surfing around the web this morning, I was stopped by Elliott Kember's "The Kember Identity." Elliott is on a quest to find the 32-character hexadecimal string that when hashed, will return itself. He has even named this string the "Kember Identity Hash" and desperately wants to find out what it is ... assuming it even exists.

I noticed a few scripts had been posted for Ruby, Python, Java and PHP, but didn't see any ColdFusion code yet. So I whipped up a version and sent it off to him. I'm sure he'll get it up there, but I thought I would also post it here as well.


<!---
    Page:        getKemberIdentity.cfm
    Author:        Stephen J. Withington, Jr. (stephenwithington.com)
    Version:    20090501.00
    Purpose:    Challenge to find a string that when hashed, will return itself.
                See http://www.elliottkember.com/kember_identity.html for more information.
--->

<cfsetting requesttimeout="360" />

<cffunction name="getKemberIdentity" access="public" output="false" returntype="string"
            hint="I try to find a string that when hashed, will return itself.">

    <cfargument name="timesToTry" type="numeric" required="true" />
    <cfset var kemberResult = "" />
    <cfset var theRandomString = "" />
    <cfset var theHashedString = "" />
    <cfset var theIndex = "" />
    <cfloop index="theIndex" from="1" to="#val(arguments.timesToTry)#" step="1">
        <cfset theRandomString = RandomizeString() />    
        <cfset theHashedString = hash(theRandomString, "MD5", "UTF-8") />
        <cfif theHashedString eq theRandomString>
            <cfset kemberResult = "We found a winner: #theRandomString# = #theHashedString# = JACKPOT!!!!" />
            <cfreturn kemberResult />
        <cfelseif theIndex eq timesToTry>
            <cfset kemberResult = "." />
        </cfif>
    </cfloop>
    <cfreturn kemberResult />
</cffunction>

<cffunction name="RandomizeString" access="public" output="false" returntype="string"
            hint="pass me a string and desired length and I'll randomize it for you.">

    <cfargument name="theString" type="string" required="false" default="0123456789ABCDEF" />
    <cfargument name="theLength" type="numeric" required="false" default="32" />
    <cfset var randomizedString = "" />
    <cfset var theIndex = "" />
    <cfloop index="theIndex" from="1" to="#val(arguments.theLength)#" step="1">
        <cfset randomizedString = randomizedString & mid(arguments.theString, rand()*len(arguments.theString)+1, 1) />
    </cfloop>
    <cfreturn randomizedString />
</cffunction>

<cfoutput>#getKemberIdentity(100000)#</cfoutput>

So what do you think? Do you think this mystery string actually exists? Want to help find out?

Comments
Wouldn't it be simply some global search heuristic that discovers this? I have written genetic algorithms, for instance, in ColdFusion but it makes more sense in this case to use something like JGAP which is written in Java. (Perhaps the title is not implying that CFML has an advantage in this.)
# Posted By Dave Babbitt | 5/5/09 1:18 PM
@Dave,

I'm sure you're probably right. You're also right in that I wasn't implying CF had any advantage of finding the mystery string any quicker than the other methods. It's just that I saw a CF script was missing from the available "Tools" to use.

I like your idea though ... maybe you could write something to discover this magical string.
# Posted By Stephen Withington | 5/5/09 1:24 PM

© 2010, Stephen J. Withington, Jr.  |  BlogCFC was created by Raymond Camden – Version 5.9.004

Creative Commons License  |  This work is licensed under a Creative Commons Attribution 3.0 Unported License.