03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

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.

Exercises ❘ 621<br />

6. The RandomNumbers example program described in the section “Generating Random<br />

Numbers” works but is long and cumbersome. Write a static MyRandom class that has a<br />

GetInt method that returns a cryptographically secure random integer. Then rewrite the<br />

example program to use the new method.<br />

7. Rewrite the program you wrote for Exercise 6 so that it generates random doubles in the<br />

range [0, 1). (Hint: Add a NextDouble method to the MyRandom class to generate the random<br />

value, and make the main program use that method.)<br />

8. Rewrite the program you wrote for Exercise 6 so that it generates integers between minimum<br />

and maximum values entered by the user. (Hint: Use the NextDouble method you added<br />

for Exercise 7 to add an overloaded version of GetInt that takes lower and upper bounds as<br />

parameters.)<br />

9. The DefaultKeyAndIV example program encrypts and decrypts a string within its button<br />

Click event handler. That’s not a reusable approach. Rewrite the program to move the encryption<br />

and decryption steps into separate methods. (Hints: Make the methods take the key and<br />

IV values as parameters. Make the main program create an AesManaged object and use its<br />

default key and IV values.)<br />

10. Modify the program you wrote for Exercise 9 to move the encryption and decryption methods<br />

into extension methods.<br />

11. Write a program similar to the one shown in Figure 27-6 to encrypt and decrypt strings. What<br />

happens if you try to decrypt a message with the wrong password What if the password is<br />

wrong only by a single character<br />

Figure 27-6: For Exercise 11, write a program that uses a password to<br />

encrypt and decrypt messages.<br />

12. Write programs to act as a sender and receiver for RSA communication. The receiver program<br />

should have these features:<br />

a. When it starts, the program should create an RSACryptoServiceProvider object<br />

associated with a key stored in a key container. (If the key already exists, it will load<br />

into the provider. If the key doesn’t yet exist, the provider will create a key and store<br />

it in the container.)<br />

b. After it has created the provider, the program should display the public key values<br />

Exponent and Modulus in TextBoxes. (You can also make it display the private data<br />

if you like.)<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!