Cryptography Reference
In-Depth Information
pk := publickey
end if;
blocksize := intlog[256](pk[1]);
blocks := bytestoblocks(convert(plaintext, bytes), blocksize);
ciphertext := Power (blocks, pk[2]) mod pk[1];
if outputformat = hex
then ciphertext := StringTools:-LowerCase (convert (ciphertext, hex));
hexsize := intlog[16](pk[1])+1;
ciphertext := map(x -> cat('$'(0, hexsize-length(x)), x), ciphertext);
cat(op(ciphertext))
elif nops(ciphertext) = 1 then
op(ciphertext)
else
ciphertext
end if;
end proc:
Example 8.3 Let us use the preceding function to encrypt a text. We are going to
use the RSA key previously defined in Example 8.2 and, specifically, the public key
with 2048-bit modulus that we have stored in the global variable pk . The text, which
does not fit in a single RSA block with this key size, is the following:
> txt := "The great struggle in cryptology during the final quarter century of the
millennium came over openness. A field that had for centuries been a secret
government monopoly exploded into public consciousness under the impact of
technology, economics, politics, and history.
David Kahn, in 'The Codebreakers' - Chap. 27 (Cryptology goes public)."
We encrypt this text with the RSA public key pk generated above and we obtain:
> ctxt := RSAEncrypt(pk, txt);
"276c9dd2a30d2f6aea94b5a0a5c5928d303d993d30977ae90d49f650e10454839b08a766b7a855ed2\
7791428cc51c4f1a5349ae563f80390989c1ea2fda47e6720895538de3c1886b53373038778691fd\
ecc3b163dc7f9d993ecf1ed08887b06b45d64ce1f23bbf4af5c37a5b83e4e4d557cd5f29e3fbe082\
769cd124f0e9b7f717a87cb98888a8b2514633926dab4b9e8c4f6ef16f3c35e7025cebd06c6d3449\
2f5746844186dc3fb55f22d0728d57ed3890c75611752f6a05f7d7c613f236e24579f52bf16b83fe\
09c50a5879d2dd1d68956a2837b9095062afb84d808556d1d2d913dd6b4787539d5a5a7588d6a2a3\
c9f927501bfa7a09352be33cfa62164610a18a6f8428b193b7d4fc4eaffd8f7fac07d2f53599d93e\
f9095d4bbfc19cf1f703d71f18813fb9e64a7df9a99740299f94bbb950d338f885209f55158f122e\
5df930eef9f14e5981fd76089deba15981a9dbadca42c78aa00d07534441a44e1cdbfebb1f6c0e7d\
7ddf4ab2e6829259a2ce84fa8b035c58e2b5ea96bb38d8ee1971633bc8241b9efe15a7c29b39cc5b\
8fd86fc9b81556d4f8daa84a23a83cf5a2ab14cbc9e6a4a4d2b6bcaa0c04fc2d88442d1225d10b57\
5f1d1099ddce20a67b4fdcd2bc718967abd1d67d186a270cc0553f554adf702cec28d8bc7746476f\
ea89a827eef16702c7a5309cec92751da563f252b58c7e2c56a040c54beb458"
In Example 8.4 below, we show how to decrypt this ciphertext using the private
key.
We now give the plain RSA decryption function. The inputs are a private key
in the format produced by RSAKeyGen and a ciphertext in the format produced
by RSAEncrypt . Actually, the private key need only be a list containing the first
6 items of a private key produced by the key generation function, because the last
two items are included only to allow a slightly different decryption procedure (see
Exercise 8.15) and are not needed by this function. The first six items in the list let
the function decrypt by means of the Chinese remainder theorem in the formwe have
described and, in fact, the function only uses items 3 to 6 in the list but it would not
work correctly if the first two were absent as they act like placeholders in this case. Of
course, it is easy to modify the key generation function to omit the modulus and the
decryption exponent if one so wishes and to modify the indexing in the decryption
function accordingly. The output of the function is the plaintext given as a text string.
Search WWH ::




Custom Search