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)())


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

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


Example 23

Suppose you want to change the text hellohowareyou to numbers:

> text2num("hellohowareyou")


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.