element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Problem in coding for RC4 security in arduino communication
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 0 replies
  • Subscribers 400 subscribers
  • Views 204 views
  • Users 0 members are here
  • serial_communications
  • arduino_sketch;
  • xbee_series_1;
  • rc4_encryption;
  • uno;
  • arduino
Related

Problem in coding for RC4 security in arduino communication

Former Member
Former Member over 12 years ago

Hello:

 

I am trying to implement RC4 encryption in MCU [i.e. Arduino UNO]. I want to set up 2 Xbee [radio] +2 Arduino for a small network where 1 Xbee+1 Arduino will work as transmitter [encrypts the data] and another set of Xbee +Arduino will receive the encrypted data and decrypt it. But before doing that I want to go step by step. So, at first I tried a code of RC4 in arduino which is connected with my PC. I checked it in arduino terminal and it worked ok.

 

Then I wanted to send the exact data which I am seeing in PC via a Xbee transmitter to another Xbee+Arduino [receiver]. The receiver is connected with my PC this time. But here I found a problem that the receiver only can capture one line at a time and shows that particular line only if I disable other Serial.print lines [but even if I enable only decryption it does not show the decrypted value in receiver]. It never shows anything at all if I try to show all the 4-5 lines [enabling all the Serial.print lines]. I think the problem is for error in my receiver code as it only takes serial data and again it is probably reading data before knowing about its size or it's existence. But I don't know how to solve it. I have been suggested to use Putty instead of the arduino terminal but still it does not show anything as a receiving end.

 

My query now is to know what modification I should make in my receiver code so that receiver can show all the output (4-5 lines) in my PC. My transmitter and receiver code is as below:

 

Transmitter:

 

#include <string.h>

 

unsigned char S[256];

char has[512];

 

#define S_SWAP(a,b) do { int t = S[a]; S[a] = S[b]; S[b] = t; } while(0)

 

void rc4(char *key, char *data){

     int i,j;

    

     Serial.print("Source : ");

     Serial.println(data);

     Serial.print("Key : ");

     Serial.println(key);

         

     for (i=0;i<256;i++){

         S[i] = i;

         //printf("%x",S[i]);

     }

    

     //printf("\n");

 

     j = 0;

     for (i=0;i<256;i++){

         j = (j+S[i]+key[i%strlen(key)]) %256;

         S_SWAP(S[i],S[j]);

         //printf("%x",S[i]);

     }

    

     //printf("\n");

     i = j = 0;

     for (int k=0;k<strlen(data);k++){

         i = (i+1) %256;

         j = (j+S[i]) %256;

         S_SWAP(S[i],S[j]);

         has[k] = data[k]^S[(S[i]+S[j]) %256];

     }

     has[strlen(data)+1] = '\0';

    

     //printf("\n");

 

}

 

void setup() {

  Serial.begin(9600);

  char key[] = "Hello";

  char sdata[] = "this is data source!";

  rc4(key,sdata);

  Serial.print("Encrypted : ");

  Serial.println(has);

  rc4(key,has);

  Serial.print("Decrypted : ");

  Serial.println(has);

 

}

 

void loop(){

 

}

 

Receiver:


void setup() {

Serial.begin(9600);

}

 

void loop(){

if(Serial.available()>0){

Serial.write(Serial.read());

  }

 

}

 

 

Thank you for your time and patience.

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube