A5/1 is a kind of stream cipher commonly used in GSM networks. This cipher scrambles data from handset to Base Trasceiver Station (BTS). This cipher consists of 3 different LFSR with different tapping and a special clocking method called “Majority Rule”. Majority rule stated that an LFSR will be clocked if middle bit is equal to majority bit and majority bit is defined as a function of all middle bit of three LFSR. Majority bit is set if at least two out of three middle bit is set, otherwise zero.
Here i presented you a way to perform RS232 serial encryption using A5/1 Algorithm. This post is basically an extension of previous post about A5/1 Implementation on PIC16f84. Previous experiment, shown me that a single bit A5/1 output costs about 82 cycles (82 micro seconds) on 4 MHz PIC16F84 microcontroller. In the other hand, RS232 specification said that the bit gap of 9600 bps asynchronous transmission is approximately 104 micro seconds.
Based on those two facts, i was encouraging my self to write another code that implements A5/1 algorithm as a serial encryptor. Since generating 1 bit A5/1 output costs 82 micro seconds and 1 bit gap of 9600 bps transmission is about 104 micro seconds, hence i concluded that A5/1 stream generation can be done while microcontroller is receiving data from RS232 terminal. The concept is basically easy, i just replace bit delay routine by bit generating process, so that 8 bit A5/1 stream is generated when 8 bit data received asynchronously through RS232.
By employing this tricky way, i can reduce the time required to process bit stream. This way also reduce gaps between two bytes. These all characteristics made A5/1 becoming a reliable candidate for RS232 encryptor application.
Now, lets talk about its reality. I coded and compiled this cipher using MPLAB v8.0 and simulated the result using Oshon Soft PIC IDE Simulator. The result was satisfactory. If you wish to apply this in such a real hardware, please use 4MHz PIC16F84 microcontroller. Please make sure that you use RA0 as transmitting bit and RA1 as receiving bit. For additional things such RS232 to TTL converter, there are many way to convert RS232 to TTL or vice versa. You can use any of them as long as it is works.
How to Use: to initialize this encryptor, follow these steps below:
- Send 3 bytes frame setting, stare from frame 0 which is MSB.
- Send 8 bytes key setting, start from key 0 which is MSB.
- Allow 16.63 ms delay for key scheduling
- Encryptor is ready to use, please use 9600 bps speed