ColdFusion Tips and Tutorials

ColdFusion Tips and Tutorials. Tips on ColdFusion, AJAX, CSS, JavaScript, HTML, Design, and more.

CFUnited Developer Conference 2010
Use this code TIPSCUST to get $100 off your registration @ CFUnited! We'll see you There!


ColdFusion Tips
Page 1 2 3
148 ColdFusion, Ajax, FuseBox, Tips, and Tut
147 Included Point of View
146 Javascript - OnFocus
145 Nathan's Rules of Professional Web Desig
144 Universal Server-Side Check | Bandwidth
143 Meeting Schedule | Identification Sessio
142 Breaking Frames Without Javascript
141 Unreal Forms
140 Screen Resolution
139 Human Help
138 Better Server-Side Validation
137 Automatic Server-Side Validation
136 Regular Expression Laboratory,ColdFusion
135 Rank-Ordered Site Search
134 Building Cryptograms
133 Well-Formed Includes
132 Grouping Families for Visits
131 Display Families on a Map Grid
130 Slide Shows
129 Determine Your Database Engine
128 ColdFusion in Context: Maxlength Lies
127 Something Extra
126 Parsing Database Structure from Data Def
125 Valid Values Maintenance
124 Print 1
123 Hide Session Id
122 Downsizing Data to Access
121 Time to Load a Page, FuseBox 4
120 Order and Rank by Subset
119 Warn through E-mail & Update on Paste Sp
118 Paste Spreadsheets, ColdFusion Component
117 Review Files Having Fixed-Length Fields
116 Organized Help
115 Sequence Slider
114 Bad Bits
113 Logical Deduction
112 Whiteout
111 Forced Navigation
110 Managing Permissions
109 Time Travel
108 Test First
107 Get Distance Between Map Coordinates
106 Validating Checkboxes
105 Matrix Manipulation
104 Field Help
103 Fake Object Not Found
102 Rank Order Correlation Coefficient
101 From Calling Pairs to Calling Tree
100 Posting Notice
99 Logout Persuasion
98 Release Session Memory
97 Use Identically Named Fields
96 Web Bug
95 Password Generation
94 Core Queries
93 Use CFFTP
92 Insert, Update, and Delete
91 Stack
90 T-Value
89 Bulk Data Entry and E-mail Validation
88 Quick Reset
87 Design 1
86 Use CFFTP
85 Support Login with AutoPost
84 Login and Site Protection
83 XY Graphs in a Graphing Calculator
82 Read Encrypted Files
81 Showing Progress
80 Frugal Cross-Browser Javascript
79 Tabbed Folders
Page 1 2 3



Custom Search
ColdFusion TIPS PLUS


Issue 00134 http://www.cftipsplus.com

I. My Comments

II. ColdFusion In Context: Building Cryptograms
By R. Martin Ladner
martin.ladner@charter.net


I. Comments:

Hope you are having a good time...

The sonogram says it will be a Healthy Boy so it looks like I will now have 3 boys.

Check out http://www.msfreepc.com


Keep Coding,
Nathan Stanford
http://www.cftipsplus.com

If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:

NathanS<at>nsnd.com

IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.

Remember this is a great way to get your name known in the
ColdFusion Community.




II. ColdFusion in Context: Building Cryptograms
By R. Martin Ladner
martin.ladner@charter.net


Suppose you have some empty space in your newsletter and a pithy quote for your readers to remember. One way to get extra mileage out of your quote is to express it as a cryptogram. As we know, cryptograms are merely simple substitution cyphers where you substitute one letter for another. Here's a way to build one.

Rearrange the Alphabet
You want to rearrange all letters so no letter keeps its original position. Put all code in crypto1.cfm. Create the alphabet with spaces between letters. There is probably a simpler starting point, but this coding is visual and easy. Use the listToArray function with delimiter of space to convert the list to an array.

Walk through the array from the end to the beginning, swapping the current position with any random position below it. (Yes, position 2 is always swapped with whatever's left in position 1, but the contents of position 1 have usually changed several times before that point, so this works.) Then convert the array back into a list. A space is used again for a delimiter here, but any delimiter consistent with the next step will work.


<!--- Rearrange alphabet so no letter keeps its position --->
<cfset StartList="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z">
<cfset StartArray=listToArray(StartList," ")>
<cfloop from=26 to=2 step=-1 index="Pos">
<cfset NewPos=randrange(1, Pos-1)>
<cfset Dummy=arraySwap(StartArray,Pos,NewPos)>
</cfloop>
<cfset EndList=arrayToList(StartArray," ")>

Remove Spaces; Show the True and Fake Alphabet
It's easy to work with these alphabets if they don't have any delimiters; so, remove them. Use the pre tag to force a monospaced font for this "key" to the puzzle. It's actually a bit awkward to get the alphabets to line up one above the other. If you use an html break, you'll get two lines. If you simply start the next variable on the next line, it will disobey the preformatting tag and show up on the same line. However, chr(10), a linefeed, will do what you want.

<!--- Remove spaces; show true and fake alphabet --->
<cfset ShowList=replace(StartList," ","","all")>
<cfset ShortList=replace(EndList," ","","all")>
<cfoutput><pre>
#ShowList##chr(10)#
#ShortList#</pre></cfoutput>

Build the Output if an Input is Present
After you set defaults and discover that an input is present, it takes a bit of thought to create an output using the fake alphabet simply and quickly. A naive method would convert one position of the input message at a time. Thus, a 200-position message would take 200 passes through 26 letters. (Ouch!) Forcing the input to capital letters and converting every A, every B, every C and so forth to its equivalent sounds good, but because you're working with the string you're changing, you'll wind up changing many characters over again to something else; this is definitely not what you want.

The key to the problem is to convert the input to upper case (for looks) but work on a copy of the input that you've forced to lower case. Convert the lower-case As to their equivalent (which will be an upper-case letter). Repeat for the lower-case Bs, and in 26 passes, you're done. Because you look for only lower-case letters, and you convert them to upper-case letters, you won't accidentally convert something you've already converted, and the puzzle takes the traditional form.


<!--- Build output if input is present --->
<cfparam name="InText" default="">
<cfparam name="OutText" default="">
<cfif len(trim(InText))>
<cfset InText=uCase(InText)>
<cfset OutText=lcase(InText)>
<cfloop from=1 to=26 index="LetterNr">
<cfset OutText=replace(OutText,lcase(chr(64+LetterNr)),mid(ShortList,LetterNr,1),"all")>
</cfloop>
</cfif>

Accept Input; Show Output
You could have just an input field and print the output to the screen, but using a field for output as well lets you see the input and output in a parallel format with similar word wraps. Use the textarea tag. Specify that word wrap should be virtual to keep Netscape happy.

<!--- Accept input; show output --->
<form action="crypto1.cfm" method="post">
<textarea name="InText" cols="60" rows="3" wrap="virtual"><cfoutput>#InText#</cfoutput></textarea>
<p>
<textarea name="OutText" cols="60" rows="3" wrap="virtual"><cfoutput>#OutText#</cfoutput></textarea>
<input type="submit" name="doit" value="Go">
</form>

Done
Browse crypto1.cfm, enter a phrase, and watch the fun. You wouldn't try to protect anything with this; but it can bring hours of enjoyment to your readers. (People buy whole books of this stuff.)

=Marty=



Publisher and Creator:
Nathan Stanford,
NathanS<at>nsnd.com
http://www.cftipsplus.com

Macromedia and ColdFusion are U.S. registered trademarks.


Copyright (c) 2000 - 2003
CFTIPSPLUS.COM and NSND.COM

Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.

Photo of Nathan Stanford
Nathan Stanford
LinkedIn

R. Marty Ladner's
Site