B.7 Examples for Chapter 9

Example 22

Suppose you need to find a large random prime of 50 digits. Here is one way. The function nextprime finds the next prime greater than x. The function rand(a..b)() gives a random integer between a and b. Combining these, we can find a prime:

> nextprime(rand(10^49..10^50)())

         73050570031667109175215303340488313456708913284291

If we repeat this procedure, we should get another prime:

> nextprime(rand(10^49..10^50)())

         97476407694931303255724326040586144145341054568331

Example 23

Suppose you want to change the text hellohowareyou to numbers:

> text2num("hellohowareyou")

                    805121215081523011805251521

Note that we are now using a = 1, b = 2, ..., z = 26, since otherwise a’s at the beginnings of messages ...

Get Introduction to Cryptography with Coding Theory, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.