30.11.2012 Views

Code and ciphers: Julius Caesar, the Enigma and the internet

Code and ciphers: Julius Caesar, the Enigma and the internet

Code and ciphers: Julius Caesar, the Enigma and the internet

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 8.3<br />

(1) Use <strong>the</strong> mid-square method to obtain four-digit numbers starting<br />

with 3317.<br />

(2) Repeat <strong>the</strong> exercise but start with 2907.<br />

(3) Repeat <strong>the</strong> exercise but start with 3127.<br />

(A calculator or computer is needed for <strong>the</strong> second <strong>and</strong> third cases.)<br />

Solutions<br />

(1) X�3317 so X 2�11 002 489. Removing <strong>the</strong> first <strong>and</strong> last pairs of digits<br />

gives <strong>the</strong> next value of X�0024 so X 2�00 000 576 <strong>and</strong> removing <strong>the</strong> first<br />

<strong>and</strong> last pairs gives <strong>the</strong> next value X�0005. Since X 2�00 000 025, <strong>the</strong><br />

next <strong>and</strong> all subsequent values of X are 0000.<br />

(2) This is a less extreme case. The values of X begin 2907, 4506, 3040<br />

<strong>and</strong> seem to be continuing satisfactorily but never<strong>the</strong>less <strong>the</strong> 42nd value<br />

of X turns out to be 0.<br />

(3) In this case cycling occurs but <strong>the</strong> sequence does not restart from<br />

<strong>the</strong> beginning. Starting with X�3127 we find that <strong>the</strong> sequence continues<br />

7781, 5439, 5827, ... but from <strong>the</strong> 38th term onwards we get 6100,<br />

2100, 4100, 8100, 6100, 4100,.... <strong>and</strong> <strong>the</strong> same four numbers now repeat<br />

indefinitely.<br />

Although mid-squaring is a conveniently simple method it should only<br />

be used, if at all, with much larger numbers than in <strong>the</strong> example.<br />

Linear congruential generators<br />

The most commonly used method generates a sequence of integers in <strong>the</strong><br />

range 0 to (M�1) by means of a recurrence formula of <strong>the</strong> type<br />

U n �AU (n�1) �B (mod M)<br />

Producing r<strong>and</strong>om numbers <strong>and</strong> letters 107<br />

where A, B <strong>and</strong> M are integers. A is called <strong>the</strong> multiplier, B is <strong>the</strong> increment<br />

<strong>and</strong> M is <strong>the</strong> modulus. The process is started off by choosing a value, known<br />

as <strong>the</strong> seed,in<strong>the</strong>range0to(M�1) for U 0 . Such a recurrence must eventually<br />

repeat <strong>and</strong> <strong>the</strong> maximum period obviously cannot exceed M, soM<br />

should be ‘large’. For suitably chosen values of A, B <strong>and</strong> M a long period is<br />

attainable. In <strong>the</strong> best cases <strong>the</strong> period is maximal <strong>and</strong> so <strong>the</strong> choice of <strong>the</strong><br />

seed is irrelevant, since all but one of <strong>the</strong> possible values (mod M) occur.<br />

The majority of r<strong>and</strong>om number generators used in computers are<br />

based upon this method with <strong>the</strong> values of <strong>the</strong> modulus, increment <strong>and</strong>

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

Saved successfully!

Ooh no, something went wrong!