[go: up one dir, main page]

0% found this document useful (0 votes)
155 views49 pages

Final Report

The document describes a secure wireless communication system project that establishes a secure wireless channel for voice communication between security personnel. The system uses RC4 encryption to encrypt voice data at the transmitter and decrypt it at the receiver. Delta modulation is used to sample the digital voice data, and Wired Equivalent Privacy (WEP) protocol provides security during wireless transmission. The project includes mobile transceiver units that enable wireless communication between security staff via a switching unit.

Uploaded by

api-3725229
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views49 pages

Final Report

The document describes a secure wireless communication system project that establishes a secure wireless channel for voice communication between security personnel. The system uses RC4 encryption to encrypt voice data at the transmitter and decrypt it at the receiver. Delta modulation is used to sample the digital voice data, and Wired Equivalent Privacy (WEP) protocol provides security during wireless transmission. The project includes mobile transceiver units that enable wireless communication between security staff via a switching unit.

Uploaded by

api-3725229
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Secure wireless communication system

FINAL YEAR PROJECT

By

Arunkumar.V
Rahul T. Nath
Sarath R
Varun Venugopal
Vipin M S

Under the guidance of


Mr. R Suresh Kumar

Department of Electrical sciences,


Amrita Institute of Technology and Science
Amritapuri
Kollam-690525
2006-2007
Acknowledgment

Our prostrations at the lotus feet of our beloved amma, Satguru Mata Amritanan-
damayi Devi;the guiding light and inspiration for all.
Firstly all thanks to our Principal Dr.K.Sankaran for giving us all the facilities for the
project thereby helping us accomplish a goal we had been dreaming of for the past cou-
ple of years.
Next we express our heartfelt gratitude to our guide Mr.R Suresh Kumar who was
unparallel in his efforts in making this project a reality. We would also like to add that
had it not been for his continuous inspiration and guidance, our project would not have
achieved even half the success that we enjoy today in its completion.
We also express our deep gratitude to Br. Jairaj for showing a keen interest in our
Surveillance System and for providing us with solutions that helped us complete our
project.
We would also like to thank our project coordinator Dr. Sundar Gopalan for provid-
ing us with all the facilities and all guidance necessary in making this project a reality.
Special thanks to Br. Karthi B for the constant support and guidance that we received.
Last we thank all the other members of the great project Security and Surveillance Sys-
tems who have helped each other in the long process of the design phase of the project.
Thanks go to all people who have helped us directly or indirectly in the literary work of
this project

1
Abstract

The system is intended to establish a secure wireless channel for communication. The
channel is to be used for voice transmission. The voice data of the personnel is first
received by the voice encoder module which converts the signal to the corresponding
digital counterpart. The data is encrypted at the transmitter using the RC4 algorithm
and decrypted at the receiver end to ensure security during communication. The digital
counterpart of the data is sampled using delta modulation. The wired equivalent pri-
vacy (WEP) protocol is used to protect data during wireless transmission. The project
consists of mobile transceiver units which enables wireless channel for communication
between security personnel with the help of the Switching Unit.

2
Contents

1 Introduction 5

2 Project Description 7
2.1 Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.1 Voice Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.2 Crypto systems . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.3 Buffering and transmission . . . . . . . . . . . . . . . . . . . . 10
2.2.4 Receiver side . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3 Project Discussion and Result 14


3.1 Implementation of RC4 . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 Designing the transmitter . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Designing the receiver . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Flow charts and circuit diagrams . . . . . . . . . . . . . . . . . . . . . 18

4 Summary and conclusion 23

5 Future Enhancements 24

A Source Codes 26
A.1 Delta modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
A.2 RC4 encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
A.3 Buffer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
A.4 Buffer 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
A.5 Receiver and decryption . . . . . . . . . . . . . . . . . . . . . . . . . 38
A.6 Demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

3
B Datasheets 46
B.1 PIC16F877A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
B.2 Wired Equivalent Privacy Protocol . . . . . . . . . . . . . . . . . . . . 47
B.3 Wireless Transmitter and Receiver Modules . . . . . . . . . . . . . . . 48

4
Chapter 1

Introduction

The secure wireless communication system is a part of the security and surveillance
system which is intended to ensure the secure wireless communication between secu-
rity personnel. The main sub categories of this high end security system are BIOMET-
RIC SENSOR, RFID, TRACKING and POSITIONING, the WIRELESS COMMU-
NICATION SYSTEM, the SWITCHING STATION and the PC INTERFACE AND
DISPLAY UNIT of which the wireless communication system plays a major role in
ensuring the security aspects of the system.
The secure wireless communication system helps security personnel to communicate
between each other within the area under the Security and Surveillance System. There
will be four mobile transceiver units which will be with people who assume the same
priority under the security hierarchy. The request for calling any other user will be pro-
cessed by the switching station and the call will be allowed if the user being requested
is not engaged in another conversation. The security of communication is ensured by
the encryption used. The modulation scheme used for efficient transfer of data is Am-
plitude Shift Keying.
Wireless systems are now a major part of many commercial organizations and network-
ing infrastructures. The benefits of cost efficiency, flexibility and rapid deployment
have been utilized on mass for many years. The wireless networking faces many se-
curity issues. In wireless communication systems an encryption algorithm is used for
security reasons. In cryptography, RC4 (also known as ARC4 or ARCFOUR) is the
most widely-used software stream cipher and is used in popular protocols such as Se-
cure Sockets Layer (SSL) and WEP (to secure wireless networks). RC4 was designed
by Ron Rivest of RSA Security in 1987; while it is officially termed ”Rivest Cipher 4”,
the RC acronym is alternatively understood to stand for ”Ron’s Code”.

5
The RC4 encryption requires secure transfer of Encryption Key. For this secure key
transfer we use Asymmetric algorithms such as RSA. The algorithm was publicly de-
scribed in 1977 by Ron Rivest, Adi Shamir and Len Adleman at MIT; the letters RSA
are the initials of their surnames. RSA is an algorithm for public-key encryption. It was
the first algorithm known to be suitable for signing as well as encryption, and one of the
first great advances in public key cryptography. RSA is still widely used in electronic
commerce protocols, and is believed to be secure given sufficiently long keys. The sys-
tem that we are trying to implement is similar to Wired Equivalent Privacy (WEP). It
is a scheme that is a part of the IEEE 802.11 standards to secure wire less networks.
Because wireless broadcasts using radio, it is particularly susceptible to eavesdropping.
WEP uses stream cipher RC4 for confidentially and the CRC-32 checksum for integrity.

Figure 1.1: Wired equelant privecy protocol

WEP relies on a secret key that is shared between a mobile station and an access point.
The secret key is used to encrypt packets before they are transmitted and an integrity
check is used to ensure that they are not modified in transit.
The RC4 initial key has two sets:
The first 24 bit keys are fixed in the two access points.
The next 24 bit is selected from a random key generation algorithm in the transmitter
side per frame and transmitted with each frame.
Key stream for a packet is generated from this initial key and one packet is encrypted
with this key stream generated. We need to initialize RC4 and generate key stream for
every frame. The 24 bit RC4 initial key is transmitted with the packet and is used in the
receiver to generate the key stream and decrypt the data.

6
Chapter 2

Project Description

2.1 Block diagram


The block diagram of the system is shown in figure 2.1

Figure 2.1: Block Diagrm

2.2 Description

2.2.1 Voice Acquisition


It consists of a microphone, amplifiers and Analog to Digital Converter. Output of the
microphone will be a weak signal which is amplified by amplifiers. ADC converts this
amplified signal into bit stream. Delta modulation was adopted as it provides consider-
able compression of data. The delta modulator consists of a PIC programmed to read

7
analog signal, digitize it using its inbuilt ADC, performs delta modulation based on
ADC output and then converts it into bytes of data. This data is then sent to the RC4
module. Proper acknowledgment is provided for synchronized communication between
these modules. The delta modulation scheme can be better understood with the help of
the algorithm.

Algorithm for Delta modulation

1. Initialize the values

2. Configure the ADC

3. Read the values from the ADC

4. Compare the previous byte of the ADC and the present byte

5. If previous value¡present value, delta equals 1 and if otherwise delta equals 0.

6. If both values are equal, the delta is the complemented bit.

7. The delta bits are then collected and then transferred in the form of bytes.

8. Before transmitting, a signal is given to the RC4 module to indicate start of trans-
mission.

2.2.2 Crypto systems


Cryptography is the study of message secrecy until modern times, cryptography re-
ferred almost exclusively to encryption. Symmetric key cryptosystems are an important
type of modern cryptosystem. Symmetric key systems are cryptosystems where same
key is used for both encryption and decryption. This class of cryptosystems is important
in modern cryptology because they are much faster than public key cryptosystems. The
two major type of symmetric key are block ciphers and stream ciphers. Block cipher
in general process the plaintext in relatively large at a time. The encryption function is
same for every block. Stream ciphers process plaintext in small blocks (some times as
small as a bit).

8
RC4

Stream ciphers are very important part of encryption algorithm. RC4 is a variable-key-
size stream cipher developed in 1987 by Ron Rivest of M.I.T. for RSA Data Security.
RC4 is used in a number of applications today. One of it most important use is in
SSL, which is used to secure most of the worlds electronics over the World Wide Web,
it is also used in IEEE802.11 wireless network security standards. RC4 is a binary
additive stream cipher. It uses a variable sized key that can be range between 8 and
2048 bits in multiples of 8 bits. This means that the core of the algorithm consist
of key stream generator function. This function generates a sequence of bits that are
then combined with the plain text with XOR. Decrypting consists of re-arranging this
key stream and XORing it to the clipper text, undoing it. The other major part of
the algorithm is the initialization function, n, which accepts a key of variable size and
uses it to create the initial state of the key stream generator. This is known as the key
scheduling algorithm. RC4 is actual a class of algorithms parameterized on the size of
its block. This parameter, n, is the word size for the algorithm. This is recommended n
= 8, but for analysis purpose it can be convenient to reduce this. Also, for extra security
it is possible to increase its value. The internal state of RC4 consists of a table of size
2n words and two word sized counters. The table is known as the S-box, and will be
known as S. It always contains a permutation of the possible 2n values of a word. The
two counters are known as i and j.
Initialisation:

1. for i=0 to 2n -1
s[i]=0

2. j=0

Scrambling:

1. For i=0 to 2n -1
j=j+S[i] +K [i mod l]
Swap(S[i], S[j])

The key scheduling algorithm of RC4 is shown above. It accepts as input the key stored
in K, and is l bytes long. It starts with the identity permutation in S and, using the key
continually swapping values to produce a new unknown key independent permutation.
Since the only action on S is to swap two values, the fact that S contains a permutation

9
is always maintained. The RC4 key stream generation is given below. It works by
continuously shuffling the permutation stored in S as time goes on, each time picking
a different value from the S permutation as output. One round of RC4 outputs an n bit
word as key stream, which can then be XORed with the plain text to produce the clipper
text.
Initialisation:

1. i=0, j=0

Generation loop:

1. i=i+1

2. j=j+S[i]

3. Swap(S[i], S[j])

4. Output z=S[S[i] +S[j]]

2.2.3 Buffering and transmission


To implement the WEP protocol(appendix B.2) we need to realise a buffer system. The
buffering section is present in both the transmitter and receiver end. In the transmitter
side there are two microcontrollers which consists of a buffer 1 and a buffer 2. The
buffer 1 receives the encrypted data from the RC4 module. When the buffer 1 is in
the process of reception, the buffer 2 will remain idle initially. When the buffer 1
controller receives bits to its maximum capacity, it enables the buffer 2 to resume the
reception of data and the buffer 1 commences the transmission of data. When the buffer
2 is done with receiving, the buffer 1 resumes the reception and the buffer 2 continues
the transmission. This procedure which involves two buffers is called a flip buffer
arrangement. The algorithm used to program the buffer section is shown below:

Buffer algorithm (Transmitter)

The transmitter needs a pair of flip buffers, the frame structure is shown in
Frame
The frame format is shown in figure 2.2
Buffer 1 Algorithm
Inputs
Frame select key from RC4 algorithm

10
Figure 2.2: WEP frame format

Data clock to detect key and data from RC4


4 byte key followed by 20 byte parallel data
Output
Store the data in the buffer 1 buffer, while send the data from the other buffer
Switch the working of buffer 1 and buffer 2, buffers on completion of every frame

1. Define buffer memory of 25 locations

2. Set the first location as the preamble

3. loop:
Wait to get a high frame select signal from the RC4 algorithm
Allow buffer 2 to send data
Prevent buffer 2 to save data
Save the data in the buffer 1 buffer
Wait to get a low frame select signal from the RC4 algorithm
Allow buffer 2to save data
Prevent buffer 2 to send data
Send the frame through the serial port

4. goto loop

Buffer 2 Algorithm
Inputs
Buffer 2 control signal from buffer 1 from RC4 algorithm
Data clock to detect key and data from RC4
4 byte key followed by 20 byte parallel data
Output
Store the data in the buffer 1, while send the data from the other buffer
Switch the working of buffer 1 and buffer 2 buffers on completion of every frame

11
1. Define buffer memory of 25 locations

2. Set the first location as the preamble

3. loop:

4. Wait to get a high buffer 2 control signal from the buffer 1 buffer
Save the data in the buffer 1 buffer
Send acknowledgment on receiving every data frame

5. Wait to get a low buffer 2 control signal from the buffer 1 buffer
Send the frame through the serial port

6. go to loop

Wireless Transmission System

A wireless transmission module of 433.92 MHz is used which uses amplitude shift
keying modulation scheme. Its data rate is 8kbps. The encrypted data which obeys the
WEP protocol is then coupled into the transmission module, where it gets transmitted.

2.2.4 Receiver side


The receiver side consists of a receiver cum decryptor and a delta demodulator.

Wireless Receiver System

The system uses a wireless receiver module (appendix B.3), which receives the trans-
mitted data and then converts into bitstream. This bit stream is then given into the
buffering and decryption block.

Reception and decryption

1. Data reception and buffering


The microcontroller will detect the preamble first from the data that comes in the
serial port thus identifies the beginning of a frame. After that it will store all the
data in to an array. The array will be of size 24 byte to store each frame.

12
2. Decryption
After storing the data, the RC4 algorithm will be executed. The key generated by
the RC4 algorithm used to decrypt the data. This process of key generation and
decryption will repeat for each byte of data. The decryption is achieved through
a XOR operation (similar to the encryption process). The decrypted data is then
given to the Delta demodulation.

Delta demodulation

Algorithm for delta modulation

1. Read the bytes of data from RC4 module.

2. According to different bits in each position we decide whether the value to be


output is to be incremented or decremented.

3. The received byte is shifted right to obtain each bit that is being sent.

4. If any particular bit is a ’1’, the data to be output is obtained by incrementing the
previous output value.

5. If it is a ’0’, the data to be output is obtained by decrementing the previous output


value.

13
Chapter 3

Project Discussion and Result

The project Secure Wireless Communication system aims at establishing a secure, effi-
cient and robust communication channel enabling a communication which guarantees
confidentiality. To ensure this security, it was necessary that the voice data be encrypted
and this was accomplished using the RC4 algorithm which is a stream cipher. The RC4
algorithm was implemented using a microcontroller which served the requirements that
the algorithm demanded. The voice data is transmitted in a frame format to the receiver.
The RC4 key was distributed in two sessions consisting of an initial 4 byte which is
transmitted and saved at the receiver end. The remaining 4 bytes is transmitted along
with the encrypted data to the receiver. The initial key transfer requires high security in
its transmission and this was met with the efficient RSA algorithm.

3.1 Implementation of RC4


As a starting step, the RC4 algorithm was analyzed and the algorithm was implemented
in C++ language. When analyzing the algorithm, we studied about the memory and
speed requirements that the algorithm demanded and we were on a lookout for the best
possible solution. The demands were well met by the PIC16F877A with which we
also had a prior experience. The algorithm had to be implemented with complexity
levels that had to have a constraint. This constraint on complexity was met with the
CCS PICC programming language which was entirely new to us. The project set start
with the implementation of RC4 algorithm for encryption and decryption of data at the
transmitter and receiver ends with the above mentioned language. The encrypted data
was sent to the receiver in a parallel fashion and the decrypted data at the receiver end
was compared with the input digital data. The result was affirmative.

14
Figure 3.1: One frame

3.2 Designing the transmitter


The voice data needs to be digitized and this is met with the in built ADC present in the
PIC. In the beginning, each output byte of ADC was sent in a frame by frame fashion
but it resulted in an unacceptable data rate of 64Kbps (8 KHz * 8bytes/sec) and more
which proved drastic for the wireless system. This led us to think about a compression
procedure which was met with Delta Modulation. Each sample corresponds to a bit of
data rather than a byte. Initially it was decided to transmit the entire 8 byte key and
the same key stream be used for the entire communication. The problem is that if a
frame is lost, the entire decryption process goes absurd leading to an undesirable result.
Also we would have to encounter the problem of jitter. The next important part of the
project was in selecting the frame format. The 8 byte key was decided to be transmitted
in two sections: the first half would be transmitted initially and the other half would be
transmitted along with the encrypted data frame. The frame consists of 20 bytes of data
(equivalent to data output of 20 ms) 4 bytes of per frame key and a byte of preamble.
The necessity of the preamble lies in detecting the start of a frame. The process of
sending half the key along with each frame has a phenomenal effect in that frame loss
does not affect the remaining transmission and decryption. The frame consists of 25
bytes which is equivalent to 10Kbps (25 * 50 * 8). The challenge that we came across
in the transmitter end was to transmit encrypted data and receive the next frame from
RC4 module simultaneously. This was overcome with the help of a FLIP buffer scheme.
It consists of a pair of buffers, one which receives the data from the RC4 module and
the other transmits the encrypted data. When one buffer gets filled with data then both
the buffers switch their tasks wherein the buffer that gets filled transmits data and the
other receives. The buffered data is then coupled into the transmitter module which has
a transmission rate of 8kbps.

15
Figure 3.2: Switching the frame

3.3 Designing the receiver


The receiver side consist of a wireless receiver module which receives the transmitted
data and sends this data into a buffer section. The operation of this buffer section was
in all means similar to that at the transmitter end. After analyzing the working at the
receiver end it was found that the time requirement at the receiver end was not as drastic
as in the transmitter. So the buffering section was incorporated into the microcontroller
which helped reduce the complexity. The encrypted data that comes into the micro-
controller is collected in the microcontroller and when it completes collecting a single
frame of data, the microcontroller outputs the frame of data to the delta demodulator.
The frame consists of 24bytes and the first 4 bytes would be the per frame key to the
microcontroller. In the demodulator, the frame of data is extracted to get the individual
bits which are demodulated and the result is given out as the output which is the final
digital counterpart of voice data. Another thing worth noticing is that, the entire data
needs to be transmitted at a data rate of 10Kbps but the data rate used here is 12.5Kbps.
The advantage of doing this is that the time that remains after receiving the data can
be utilized in decrypting the data and also for sending to the demodulator for obtaining
the digital counterpart of the voice data thus reducing the hardware complexity. The
reception and decryption can be better understood with the help of the diagram shown
in figure3.3. During the process of the project, we had come across a lot of challenges
at each and every phase of the literary work of the project. The main problem that the
team encountered was in the timing synchronization and solving this provided us with a
punch of satisfaction. The project SECURE WIRELESS COMMUNICATION has suc-
ceeded in achieving its primary objective of establishing a secure and robust channel

16
Figure 3.3: Reception and decryption

thus playing its part in the SECURE SURVEILLANCE SYSTEM.

17
3.4 Flow charts and circuit diagrams

Figure 3.4: Delta modulation

18
Figure 3.5: RC4 encryption

19
Figure 3.6: Buffer

20
Figure 3.7: Transmitter

21
Figure 3.8: Receiver

22
Chapter 4

Summary and conclusion

The Secure Wireless Communication System is an integral part of the Security and
Surveillance System. The security and surveillance system is a high end security en-
sured system comprising of biometric sensors, RFID authentication, tracking and posi-
tioning system, secure wireless communication system, switching station and interfac-
ing and display unit. It allows secure voice communication between security personnel
within the security and surveillance system. Security is a major challenge faced by
wireless communication systems. The security of communication channel is ensured
using the encryption technique being employed. Efficient transmission of data through
the channel requires modulation for which we use the amplitude shift keying technique.
Both the transmitter and receiver ends were modeled in real time and the secure
communication channel between the security personnel were established.

23
Chapter 5

Future Enhancements

The system in its present state is a simplex communication system i.e. it consists of a
single transmitter and receiver. In future it needs to be modeled as a full duplex system.
The number of users needs to be incremented and this demands an efficient multiple
access technique such as the CDMA. Also control signals have to be incorporated which
enables communication with the base station.

24
Bibliography

[1] Rick Wash,” Lecture Notes on RC4 and Stream Ciphers”.

[2] ”‘RSA Hardware Implementation”,RSA Laboratories technical re-


port TR-801.10, April 19, 1996.

[3] ”‘PIC16F87XA Data Sheet”’, 28/40/44-Pin Enhanced Flash Micro-


controllers, Microchip

[4] ”‘C Compiler Reference Manual”’,Custom Computer Services Inc.,


August 2002

[5] Wired Equivalent Privacy Protocol.pdf

[6] Simon Haykin,”’Digital communication”’,4/e,Wiley and Sons pvt


ltd.

25
Appendix A

Source Codes

A.1 Delta modulation


//program to configure ADC, read values from it and delta modulate
//~~~~~~2BYtes TXN~~~~~~~~~
#include<16f877a.h>
#define stat_adc 0x8
#define samp_clock PIN_B0

void main(void)
{

//initialization
int count=0,delout=0,delta=0,byt_count=0,out_data[2],byt=0;
long int adc_out,prev_adc=0;
out_data[0]=0x00;
out_data[1]=0x00;
set_tris_b(0x03);
set_tris_c(0x00);
output_c(0x00);

//~~~configure ADC~~~
setup_adc_ports(AN0_VREF_VREF);
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel( 0 );

26
//*****reading from ADC*****
output_c(0x00);
loop:

while (!input(samp_clock)); //waits for sampling clock 8khz to go high


adc_out=read_adc();
if(byt_count>=20)
byt_count=0;

if(byt_count==0)

output_high(PIN_B2); //ackno for RC4 module: DTR1

//else
//output_low(PIN_B2);

count++;
if(count>8)
count=1;

delout<<=1; //left shift once

if(prev_adc<=adc_out) //delta modulation


{
delta=1;
}
else if(prev_adc>adc_out)
{
delta=0;
}
else
{
delta=!delta;

27
}

delout+=delta;

prev_adc=adc_out;

if(count==8)
{
out_data[byt]=delout;
delout=0;
byt_count++;
byt++;

if(byt>=2) //outporting data to RC4module


{
output_c(out_data[0]);
output_high(PIN_B3); //ackno for RC4 module: DTR21
while(!input(PIN_B1)); //waits for ack from RC4 module :RDT1
output_low(PIN_B3);

output_c(out_data[1]);
output_high(PIN_B3); //ackno for RC4 module: DTR22
while(!input(PIN_B1)); //waits for ack from RC4 module :RDT2
output_low(PIN_B3);
byt=0;
}
}
while (input(samp_clock)); //waits for sampling clock to go low

goto loop;

28
A.2 RC4 encryption
//------------------RC4 ENCRYPTION program-------------------
#include<16f877a.h>

void main(void)
{
//------------Initialization-----------
int temp,i,j,x,y,k,a,b,sa,z=0,p=0,sb=0;
int pf_key=0,count=0,en_data,fm_start=0,count_byte=0;
int xout[2];

set_tris_c(0xff);
set_tris_b(0x00);
set_tris_d(0xff);
set_tris_e(0x00);
output_b(0x00); //clearing the PORT B register
//output_c(0x00); //clearing the PORT C register
//output_d(0x00); //clearing the PORT D register

start:

for(i=00;i<80;++i)
write_bank(1,i,i);

for(j=00;j<96;++j)
write_bank(2,j,j+80);

for(j=00;j<=80;++j)
write_bank(3,j,j+176);

for(j=180;j<=183;++j)
write_bank(3,j-100,02);

for(j=184;j<=187;++j)

29
write_bank(3,j-100,07);

j=0;i=0;
//--------SCRAMBLING----------
do
{
if(i<80)
x=read_bank(1,i);
else if (i<176)
x=read_bank(2,i-80);
else if (i<=254)
x=read_bank(3,i-176);
else if(i==255)
x=read_bank(3,i-176);

y=read_bank(3,80+i%8);

temp=x;
j=j+x+y;
j=j%256;

if(j<80)
y=read_bank(1,j);
else if (j<176)
y=read_bank(2,j-80);
else if (j<=254)
y=read_bank(3,j-176);
else if (j==255)
y=read_bank(3,j-176);

x=y;

if(i<80)
write_bank(1,i,y);

30
else if (i<176)
write_bank(2,i-80,y);
else if (i<=254)
write_bank(3,i-176,y);
else if (i==255)
write_bank(3,i-176,y);

y=temp;

if(j<80)
write_bank(1,j,y);
else if (j<176)
write_bank(2,j-80,y);
else if (j<=254)
write_bank(3,j-176,y);
else if (j==255)
write_bank(3,j-176,y);
i++;

}while(i<=254);

//-----------PER FRAME KEY GENERATION-----------

count=0;
while(!input(PIN_C2)); //from delta modulation(C2)
fm_start=!fm_start;
output_bit(PIN_C0,(fm_start));

for(j=184;j<=187;++j) // per frame key transfer


{
++count; // to the buffer
pf_key=read_bank(3,j-100);
output_b(pf_key);
output_high(PIN_C3); //Request to buffer(C3)

31
while(!input(PIN_C4)); //Acknoledgement to buffer(C4)
output_low(PIN_C3);

}
//------PSEUDO RANDOM GENERATION------
i=0;
j=0;
temp=0;
z=0;
repeat:
for(k=0;k<2;++k) //Receiving 2byte data
{
while ( !input(PIN_C5) ); // Information from delta (C5)
xout[k]=input_d(); // reception
output_high(PIN_C6); // Acknoledgement to delta (C6)
#use delay (clock=20000000)
delay_us( 20);
output_low(PIN_C6); // Reset Acknoledgement to delta (C6)
}
count_byte=0;
//-------Generation loop-----------

for(k=0;k<2;++k)
{
i=i+1;
p=i%256;
if(p<80)
x=read_bank(1,p);
else if (p<176)
x=read_bank(2,p-80);
else if (p<=254)
x=read_bank(3,p-176);
else if (p==255)
x=read_bank(3,p-176);

j=(j+x)%256;

32
if(i<80)
x=read_bank(1,i);
else if (i<176)
x=read_bank(2,i-80);
else if (i<=254)
x=read_bank(3,i-176);
else if (i==255)
x=read_bank(3,i-176);

if(j<80)
y=read_bank(1,j);
else if (j<176)
y=read_bank(2,j-80);
else if (j<=254)
y=read_bank(3,j-176);
else if (j==255)
y=read_bank(3,j-176);
temp=x;
x=y;

if(i<80)
write_bank(1,i,y);
else if (i<176)
write_bank(2,i-80,y);
else if (i<=254)
write_bank(3,i-176,y);
else if (i==255)
write_bank(3,i-176,y);

y=temp;

if(j<80)
write_bank(1,j,y);
else if (j<176)
write_bank(2,j-80,y);

33
else if (j<=254)
write_bank(3,j-176,y);
else if (j==255)
write_bank(3,j-176,y);
//...........................................

sa=y;
b=i%256;
if(b<80)
sb=read_bank(1,b);
else if (b<176)
sb=read_bank(2,b-80);
else if (b<=254)
sb=read_bank(3,b-176);
else if (b==255)
sb=read_bank(3,b-176);

a=(sa+sb)%256;

if(a<80)
z=read_bank(1,a);
else if (a<176)
z=read_bank(2,a-80);
else if (a<=254)
z=read_bank(3,a-176);
else if (a==255)
z=read_bank(3,a-176);

en_data=z^xout[k];
output_b(en_data); // To the output port
output_high(PIN_C3); // Information to buffer (C3)
while(!input(PIN_C4)); // Acknoledgement from buffer(C4)
output_low(PIN_C3); // Reset Information to buffer (C3)
++count;
++count_byte;
}

34
if(count>=23)
goto start;
if(count_byte>=2)
goto repeat;

A.3 Buffer 1
//Buffer_1 (Master)
#include<16f877a.h>

#define FRAME_SELECT PIN_B0 //IN


#define DATA_CLK PIN_B1 //IN
#define DATA_ACKNOW PIN_B2 //OUT
#define SLAVE_CONTROL PIN_B3 //OUT
#define TRANS_ENABLE PIN_B4 //OUT

#define ALL_IN 0XFF


#define ALL_OUT 0X00
#define HIGH output_high
#define LOW output_low
#define CONTROL_B 0X03
#define PREAMPLE 0XFF

#use delay (clock=20000000)


#use rs232(baud=12500, xmit=PIN_C6, rcv=PIN_C7,stream=rs232)

void main()
{
int buffer[25],pos=0;
set_tris_d(ALL_IN);

35
set_tris_e(0X00);
set_tris_c(ALL_IN);
set_tris_b(CONTROL_B);
buffer[0]=PREAMPLE;
LOW(TRANS_ENABLE);
LOW(DATA_ACKNOW);
LOW(SLAVE_CONTROL);
loop:
while (!input(FRAME_SELECT));
LOW(SLAVE_CONTROL);
pos=1;
do{
while (!input(DATA_CLK));
buffer[pos]=input_d();
HIGH(DATA_ACKNOW);
Pos++;
while (input(DATA_CLK));
LOW(DATA_ACKNOW);
}while (pos<23);

while (input(FRAME_SELECT));
HIGH(SLAVE_CONTROL);
HIGH(TRANS_ENABLE);
pos=0;
do{
putc(buffer[pos]);
pos++;
// delay_us(50);
}while(pos<25);
LOW(TRANS_ENABLE);
goto loop;

36
A.4 Buffer 2
//BUFFER_2 (Slave)
#include<16f877a.h>

#define SLAVE_CONTROL PIN_B0 //IN


#define DATA_CLK PIN_B1 //IN
#define DATA_ACKNOW PIN_B2 //OUT
#define TRANS_ENABLE PIN_B3 //OUT

#define ALL_IN 0XFF


#define ALL_OUT 0X00
#define HIGH output_high
#define LOW output_low
#define CONTROL_B 0X03
#define PREAMPLE 0XFF

#use delay (clock=20000000)


#use rs232(baud=12500, xmit=PIN_C6, rcv=PIN_C7,stream=rs232)

void main()
{
int buffer[25],pos=0;
set_tris_d(ALL_IN);
set_tris_e(0X00);
set_tris_c(ALL_IN);
set_tris_b(CONTROL_B);
buffer[0]=PREAMPLE;
LOW(TRANS_ENABLE);
LOW(DATA_ACKNOW);

loop:
while (!input(SLAVE_CONTROL));
pos=1;

37
do{
while (!input(DATA_CLK));
buffer[pos]=input_d();
HIGH(DATA_ACKNOW);
pos++;
while (input(DATA_CLK));
LOW(DATA_ACKNOW);
}while (pos<25);

while (input(SLAVE_CONTROL));
HIGH(TRANS_ENABLE);
pos=0;
do{
putc(buffer[pos]);
pos++;
//delay_us(50);
}while(pos<23);
LOW(TRANS_ENABLE);
goto loop;
}

A.5 Receiver and decryption


//--------RC4 DECRYPTION program-------
#include<16f877a.h>
#define HIGH output_high
#define LOW output_low
#define ALL_IN 0XFF
#define ALL_OUT 0X00
#define PREAMBLE 0XFF
#bit STATUS=0X0C.5
#use delay(clock=20000000)
#use rs232(baud=12500, xmit=PIN_C6, rcv=PIN_C7,stream=rs232)

38
void main(void)
{
//----------Initialization-----------
int data=0,pos=0,buffer[24],temp;
int i,j,x,y,a,b,sa,z=0,p=0,sb=0,pf_key=0,count=0,de_data;
set_tris_c(ALL_IN);
set_tris_d(ALL_OUT);
set_tris_e(0X00);
set_tris_b(0x00); //output of the rc4 (key)is in port b
set_tris_e(0x00);
output_b(0x00); //clearing the PORT B register

start:
//RECEiVING THE FRAME
data=0;
count=0;
do{
data=getc();
}while(data!=PREAMBLE);
pos=0;
do
{
while(STATUS==0);
buffer[pos]=getc();
HIGH(PIN_D2);
LOW(PIN_D2);
++pos;

}while (pos<25);
for(i=00;i<80;++i)
write_bank(1,i,i);

for(j=00;j<96;++j)
write_bank(2,j,j+80);

39
for(j=00;j<=80;++j)
write_bank(3,j,j+176);

for(j=180;j<=183;++j)
write_bank(3,j-100,02);

for(j=184;j<=187;++j)
write_bank(3,j-100,07);

//------scrambling-------
j=0;i=0;
do{
if(i<80)x=read_bank(1,i);
else if (i<176)
x=read_bank(2,i-80);
else if (i<=254)
x=read_bank(3,i-176);
else if(i==255)
x=read_bank(3,i-176);
y=read_bank(3,80+i%8);
temp=x; j=j+x+y;j=j%256;
if(j<80)
y=read_bank(1,j);
else if (j<176)
y=read_bank(2,j-80);
else if (j<=254)
y=read_bank(3,j-176);
else if (j==255)
y=read_bank(3,j-176);
x=y;
if(i<80)
write_bank(1,i,y);
else if (i<176)
write_bank(2,i-80,y);
else if (i<=254)
write_bank(3,i-176,y);

40
else if (i==255)
write_bank(3,i-176,y);
y=temp;
if(j<80)
write_bank(1,j,y);
else if (j<176)
write_bank(2,j-80,y);
else if (j<=254)
write_bank(3,j-176,y);
else if (j==255)
write_bank(3,j-176,y);
i++;
}while(i<=254);

//------------- per frame key reception------------


count=0;
for(j=184;j<=187;++j)
{
++count;
pf_key=buffer[count]; //receiving the per frame key
write_bank(3,j-100,pf_key); //writing the pf_key to memory
}

loop:
//pseudo random generation
i=0;j=0;temp=0;z=0;
//------------generation loop----------
i=i+1;
p=i%256;
if(p<80)
x=read_bank(1,p);
else if (p<176)
x=read_bank(2,p-80);
else if (p<=254)
x=read_bank(3,p-176);
else if (p==255)

41
x=read_bank(3,p-176);
j=(j+x)%256;
if(i<80)x=read_bank(1,i);
else if (i<176)
x=read_bank(2,i-80);
else if (i<=254)
x=read_bank(3,i-176);
else if (i==255)x=
read_bank(3,i-176);
if(j<80)
y=read_bank(1,j);
else if (j<176)
y=read_bank(2,j-80);
else if (j<=254)
y=read_bank(3,j-176);
else if (j==255)
y=read_bank(3,j-176);
temp=x;x=y;
if(i<80)
write_bank(1,i,y);
else if (i<176)
write_bank(2,i-80,y);
else if (i<=254)
write_bank(3,i-176,y);
else if (i==255)
write_bank(3,i-176,y);y=temp;
if(j<80)
write_bank(1,j,y);
else if (j<176)
write_bank(2,j-80,y);
else if (j<=254)
write_bank(3,j-176,y);
else if (j==255)
write_bank(3,j-176,y);

sa=y;b=i%256;

42
if(b<80)
sb=read_bank(1,b);
else if (b<176)
sb=read_bank(2,b-80);
else if (b<=254)
sb=read_bank(3,b-176);
else if (b==255)
sb=read_bank(3,b-176);
a=(sa+sb)%256;
if(a<80)z=read_bank(1,a);
else if (a<176) z=read_bank(2,a-80);
else if (a<=254)z=read_bank(3,a-176);
else if (a==255) z=read_bank(3,a-176);
++count;
data=buffer[count];
de_data=z^data; //Decryption
output_b(de_data); // To the output port
output_high(PIN_d0); // Information to DAC (C3)
while(!input(PIN_C4)); //Acknoledgement from DAC(C4)
output_low(PIN_d0); // Reset Information to DAC (C3)
if(count>=24)
goto start;
goto loop;

A.6 Demodulation
//RECEIVE DATA , DO DELTA DEMODULATION AND TO DAC
#include<16f877a.h>

#define RTD PIN_D0


#define DTR PIN_D4

43
#use delay(clock=4000000)
#byte rcv_val=0x51
#bit test_bit7=0x51.7
#byte check=0x52
#bit check_bit=0x52.0

void main(void) //###start of main###


{

int dac_val=0x7f,i=0,rcv_var[20],count=0,j=0;//dat=0x00;

set_tris_b(0x00); //output port


set_tris_c(0xFF); //input port
set_tris_d(0x0F); //for acknowledgements-0 1 2 3 input
// 4 5 6 7 output
LOOP:
count=0;
//~~~~~receiving data from RC4 module~~~~~

do
{
while(!input(RTD)); //wait for ackno HIGH from RC4 module
rcv_var[count]=input_c();
count++;
output_high(DTR); // ackno to RC4 module
while(input(RTD)); //wait for ackno LOW from RC4 module
output_low(DTR); // ackno to RC4 module
}while(count<20);

//~~~~~DELTA demodln and outporting~~~~~


j=0;
do
{
rcv_val=rcv_var[j];
i=0;

44
do
{
check=shift_left(&rcv_val,1,0);
if(check_bit==1)
{
if(dac_val!=0xFF)
dac_val++;
}
else
{
if(dac_val!=0x00)
dac_val--;
}
delay_us(85);
output_b(dac_val);
i++;
}while(i<8);
j++;
}while(j<20);
goto LOOP;

45
Appendix B

Datasheets

B.1 PIC16F877A

MICROCHIP
Data Sheet
28/40/44-Pin Enhanced Flash
Microcontrollers

46
B.2 Wired Equivalent Privacy Protocol

A scheme to secure IEEE 802.11 wireless networks

47
B.3 Wireless Transmitter and Receiver Modules

WEN SHING
DATA SHEET

48

You might also like