O'Reilly logo

JavaScript Application Cookbook by Jerry Bradenbaugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Ciphers in JavaScript

Application FeaturesJavaScript Techniques
• Message Encryption Application Using Multiple Ciphers• Assigning Methods to Your Objects
• Object-Oriented Design Makes Adding Ciphers Easy• More String Matching and Replacing
• Entertaining Application and Utility for Your Visitors• Tapping into JavaScript Object Inheritance
 • Using Alternate Syntax

If you just finished the previous chapter, this one will give your brain a little breather. This chapter is lighter and deals with an application based on pure, simple fun—ciphering techniques with JavaScript. The application jumbles text messages into what seems like a bunch of junk, meaningful only to those who possess the key to reveal its secret.

This interface displayed in Figure 9.1 is fairly simple. With the Caesar cipher selected, it’s just a paragraph describing the cipher, a select list used to choose a number key, and a text area to enter text to encipher and decipher.

The cipher interface

Figure 9-1. The cipher interface

The text “JavaScript is the scripting language of choice across the planet, don’t you agree?” is entered in the text area. Selecting 6 from the Shift list, then choosing the “Encipher” button yields the scrambled text you see in Figure 9.2. Here it is again:

pg1gyixovz oy znk yixovzotm rgtm0gmk ul inuoik jutz 4u0 gmxkk

Figure 9-2. Using the Caesar cipher

Choosing “Decipher” ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required