Lab 4 Introduction
In this lab, we implement RSA encryption on the BF561. Labs using the software generated in this lab could be coupled with communication software to build a complete encrypted communication device.
As a review of encryption, ou may wish to read the following Wikipedia articles
- http://en.wikipedia.org/wiki/Public-key_encryption
- http://en.wikipedia.org/wiki/RSA
- http://en.wikipedia.org/wiki/Exponentiation_by_squaring
Following the RSA example in the Wikipedia article, assume the following values: p = 61, q = 53, r = 17, s = 2753, n = p X q = 3233. Transforming a character, x, into an encrypted character c may be done using equation (1). Similarly, transforming a character, x, into an decrypted character d may be done using equation (2).
decrypt(x) = xs mod n = d (2)
To implement such equations in C, you may need to some of write the following:
- code to determine the number of bits required to represent a decimal number
- code to determine the ``bit state'' of the ith bit in a binary representation (i.e., 0 or 1)
- the Square-and-Multiply algorithm
- a binary exponentiaion algorithm or modular exponentiation algorithm
Encryption Mode
Use the fopen()
function from stdio.h to read the file
0ws3410.txt
For each line in the text file, encrypt each character using the keys
above. For preliminary testing, print the encrypted character to the Visual DSP++ console using
printf()
. Then rewrite the code to use a #define
macro as in Labs #2 and #3 to either print
the encryped text to the console or to an RS232 communication device using UART_putc
and/or
UART_puts
.
Decryption Mode
Use the UART getc and/or UART gets functions from UART Library.h to read in an ecrypted line of text. Write the code such that the program will always print it to the console (using printf() 9- but will only decrypt the line if a push button has been pressed. Also, if another button is pressed, the program will forgo decryption and will print the encrypted line - draw a FSM diagram representing this functionality.