15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

446<br />

Book IV: Algorithms<br />

each letter with the third letter from the current letter. So the letter A would<br />

be replaced by the letter D, the letter B by the letter E, and so on. In this<br />

case, the method is the same, but the implementation is slightly different<br />

while being only marginally harder to decipher.<br />

Although substitution ciphers are easy to implement, they’re also easy to<br />

break. After you know to replace a letter in the ciphertext by another letter<br />

that’s shifted by a specific distance in the alphabet (such as the third letter),<br />

you can easily break the code. One way to avoid this problem is to use a onetime<br />

pad, which consists of a series of random numbers that tell how far to<br />

shift the next letter in a message. So a one-time pad might contain three<br />

random numbers, like this:<br />

2 7 –3<br />

The first number (2) tells the algorithm to shift the first letter of the text by<br />

two letters. So if the first three letters of the message are SAM, the first<br />

letter, S, would get replaced by the second letter from S in the alphabet,<br />

which is U.<br />

The second number (7) tells the algorithm to shift the second letter by<br />

seven letters. So the letter A gets replaced by the seventh letter down, which<br />

is H. Finally, the third number (3) tells the algorithm to shift the third letter<br />

by the third letter down, so the letter M gets replaced by the letter P. Now<br />

the entire message SAM gets encrypted as the ciphertext UHP.<br />

The one-time pad gets its name because the random series of numbers are<br />

used only once. Now it’s virtually impossible <strong>for</strong> anyone to discover how the<br />

letters are substituted because the replacement letters are picked at random.<br />

The only way to decipher this ciphertext is to get a copy of the one-time pad.<br />

Of course, the one-time pad has its drawbacks. To work, both parties need a<br />

copy of the same one-time pad. If you could transfer a copy of the one-time<br />

pad securely, you might as well transfer the message you’re delivering<br />

instead. Also, one-time pads can be used only once. If they’re used more<br />

than once, someone can eventually guess the random pattern of letters.<br />

Even worse is that a one-time pad must specify how far to shift each letter in<br />

a message. If you’re encrypting a message consisting of 1,000 letters, you<br />

need a one-time pad to specify how to shift all 1,000 letters. If you’re encrypting<br />

a message consisting of 10,000 letters, you need a one-time pad that<br />

specifies how to shift all 10,000 letters.<br />

Given these problems, one-time pads are generally impractical <strong>for</strong> normal use.<br />

A slight variation of the one-time pad is the use of a password. A password acts<br />

like a one-time pad; instead of defining how to alter each individual character

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!