The Hardware Side of Cryptography

15 June 2008

Implementing the RC4 stream cipher on PIC18F4550

Filed under: encryption — Tags: , , , , — edipermadi @ 12:29 pm

Today, i’m started developing RC4 cipher on PIC18F4550. This cipher was originally developed by Ron Rivest for RSA Security as a trade secret. Eventually, someone posted it to Cypherpunks and sci.crypt Mailing List. Now, RC4 belong to everyone who want to use it🙂 . You may note that the cipher was pretty simple and straightforward. However, since this cipher require large size of RAM for computation. I decided to write the code on PIC18F4550 instead of PIC16F877.

After sitting for more than six hours, finally i was able to code RC4 stream cipher for PIC18F4550. That was an enjoyful moment to me. The code was developed and simulated using MPLAB v8.0 and some PHP script to simulate encryption byte per byte, of course to ensure that everything is under control.

RC4 was the fastest cipher i have ever coded, it reach almost 25 cycles per byte 8) , That was amazing, 8) . See two screenshots below and feel free to use and modify the code under the term of GNU Public License v3.0. Have a nice day and happy coding😀 .

Plain Text

Cipher Text


Source Code v1.0
PIC18F4550 Datasheet
MPLAB v8.0

RC4 Cipher
Ron Rivest
RSA Security


  1. Do you have any script in C?

    Comment by Paul Hodel — 13 June 2009 @ 2:25 am

    • @Paul :
      hi, thank you for visiting my blog. I have the code in C. i’ll send it to your email.

      Comment by edipermadi — 15 June 2009 @ 10:26 am

  2. Do you have RC4 in C?
    i hope u send RC4 script(in C) to my email?
    i want to create a RC4 encrypt funtion in postgresql with C..
    thank u very much…

    Comment by pram — 16 June 2009 @ 10:33 pm

    • @pram :
      Hi, thank you for your visit to my blog. I sent the code to ur email.

      good luck

      Comment by edipermadi — 17 June 2009 @ 5:55 pm

  3. Please send me the C code.
    Thank you very much,


    Comment by Eduardo (Brazil) — 3 October 2009 @ 10:11 pm

    • @Eduardo

      sorry, i dont have the c code at this moment😀 .

      Comment by edipermadi — 5 October 2009 @ 10:41 am

  4. have you please the implementation of Ellitpic curve cryptography on PIC18F4550

    thank u very much…

    Comment by Moez — 29 December 2009 @ 7:05 pm

    • @moez:
      sorry, i have not create any ECC implementation on PIC18F4550 and i actually have no idea about it😀. if you have some suggestion please send me a message

      Comment by edipermadi — 8 January 2010 @ 9:23 am

  5. do u have RC4 cipher in c …. plz snd me ….

    Comment by anita — 13 January 2010 @ 6:05 pm

  6. Elliptic curve cryptography (ecc) is an asymetric algorithm, applied for authentification protocols such as elliptic curve digital signature algorithm (ECDSA), if you are interseted about, i will send you will be very interessant to implement n pic. thanks .

    Comment by moez — 17 March 2010 @ 4:16 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: