Cryptography Reference
In-Depth Information
Exercise 3.15 Give an alternative Maple procedure to generate a list of pseudo-
random bytes from a seed, using the option numbits = 8 in each call to NewBit
Generator .
Example 3.7 Suppose that we want to use the number 9234876983328430757 as
seed to generate a sequence of 256 bytes, using the modulus which is a product of
two 1024-bit primes. We do the following (without printing the output):
> BBSByteGen(9234876983328430757, 256):
Now, the same sequence of bytes, given as a hex string, would be:
> BBSByteGen(9234876983328430757, 256, format = hex);
"4a7a15beff9af7b6a28d7d5e23f55bf38725bbfc92c805ed1f69a363cbcd9491d2a0b1523e2f2a7b4\
df49995e7acb0568ac397d7c04210a7a3174b7c8c46b7c0f5a554b6199699dd809637cd68536b5c8\
3fd3b410ab1aa10f6e0553ae5147b9adfc044d1f62a642d588d80f1bbb1e98d1a840e343b9b0792a\
c0580f99524a03308dbc4d52a53740efcec4935af150cd0ac0ec22960166e524ce74678e9b83636a\
b43eab15332dbb95eaa0f8a53e97b9bd08917ae06810303f8c3429c4b2a995fd3794f63ee03a536e\
55779c3a9af55c30f881085fa7ed563fb7536497b99662f0cac11854ede3f4405471055670f5d618\
472be584ec16ab940fdc7e280c6d623"
In Definition 3.5, we described the pseudo-random one-time pad as an encryption
scheme with fixed-length messages of binary length
. In practice, we will allow
messages of variable length and to encrypt them we will generate a list of pseudo-
random bytes of the required length.
The next procedure implements the encryption/decryption function for this
scheme and makes use of several functions from Appendix A, including string
posint , which will often be used to convert seeds or keys to decimal form. The
first required parameter is for the key, which can be either a positive integer (in dec-
imal form) or an even-length hex string that can also be regarded as the base-256
expansion of a positive integer where, in order to eliminate ambiguity, each base-
256 digit is represented, as already explained, by two hex digits. The second required
parameter is message , which will take as value the plaintext when encrypting and
the ciphertext when decrypting. In the first case the message is an ASCII text string
but ciphertexts will always be hex strings to ensure that they are printable. The
third parameter, action , is optional and the permitted values are 'encrypt' and
'decrypt' , with the former being the default.
Finally, there is another optional keyword parameter bbslength with the same
purpose as in the function BBSByteGen above. The output is either the ciphertext
(a hex string) or the plaintext (a text string).
(
n
)
> POTP := proc(key::{posint, string}, message::string, action::name := 'encrypt',
{bbslength::{512, 768, 1024} := 1024})
local k, l, m, blist;
uses StringTools;
if action = 'encrypt' then
l := Length(message);
m := convert(message, bytes)
elif action = 'decrypt' then
if not IsHexDigit(message) then
error "Ciphertext must be a hex string"
end if;
m := hexstringtobytes(message);
Search WWH ::




Custom Search