It performs an XOR on each character in the string with the corresponding
character in the key. If it gets to the end of the key, it starts again at
the first character in the key. The result of each of these operations is
formated as a 2 character HEX representation of it's ascii number.

As has been mentioned, it's very weak.

The code below should show provide a reasonable explanation of how it works.

*********************************************
<cfset string = "This is some text">
<cfset key = "key">
<cfoutput>#cfusion_encrypt(string,key)#</cfoutput>

<!--- This bit just builds a key that is the same length as the string --->
<cfif len(string) GT len(key)>
<cfset newKey = repeatString(key,int(len(string)/len(key)))>
<cfif len(string) GT len(newKey)>
<cfset newkey = newKey & left(key,len(string)-len(newkey))>
</cfif>
<cfelse>
<cfset newKey = key>
</cfif>

<!--- Initialize the encryption result --->
<cfset newString = "">

<!--- Encrypt one char at a time --->
<cfloop from="1" to="#len(string)#" index="i">
<cfset stringChar = mid(string,i,1)>
<cfset keyChar = mid(newKey,i,1)>
<cfset newChar =
formatBaseN(bitXor(asc(stringChar),asc(keyChar)),16)>
<cfif len(newChar) EQ 1>
<cfset newChar = 0 & newChar>
</cfif>
<cfset newString = newString & ucase(newChar)>
</cfloop>

<cfoutput><br >#newString#</cfoutput>
**********************************************

Spike

--------------------------------------------
Stephen Milligan
Code poet for hire
http://www.spike.org.uk

Do you cfeclipse? http://cfeclipse.tigris.org


>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] On Behalf Of Eric Jones
>Sent: Thursday, August 19, 2004 12:12 PM
>To: CF-Talk
>Subject: RE: cf_encrypt()
>
>VERY basic. It only returns a string with letters and numbers. Nothing
>"special" about it.... not sure if it's any particular
>algorithm, or just
>something MM came up with... Would be nice to know, so if
>anyone has any
>details please post to list :)
>
>ERJ
>  -----Original Message-----
>  From: Willy Ray [mailto:[EMAIL PROTECTED]
>  Sent: Thursday, August 19, 2004 3:11 PM
>  To: CF-Talk
>  Subject: cf_encrypt()
>
>
>  Does anybody know what kind of encryption cf_encrypt() is using?
>
>  Willy
>
>  -----
>  Willy Ray
>  Web Applications Developer
>  Certified Advanced ColdFusion Developer
>  Westminster College
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to