Encryption of text read from a PS2 Keyboard

Hi all,

I have a PS2 Keyboard, a 16x2 LCD and an arduino wired up.

In one program all PS2 Key presses are successfully displayed on LCD and these are stored in a character array of size 20.

In another separate program i have implemented a Substitution Cipher technique where all key presses are shifted with 13 characters, i.e. If i press “A” on keyboard,it prints “N” on LCD. If “B” pressed it prints “O” on LCD.

Both programs run successfully.

Now the problem here is, both are separate programs, and what i want to do is that the data in array should be Ciphered using Substitution technique. Need to combine both programs appropriately.

Thanks. :slight_smile:

Displaying text in Array:

#include <LiquidCrystal.h>
#include <PS2Keyboard.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 13, 14, 15, 16, 17);

const int DataPin = 2;
const int IRQpin =  3;

char InputMsg[20];
static int i = 0;
char KbChars;


PS2Keyboard keyboard;
 

void setup() {
  lcd.begin(16, 2);
  delay(100);
  keyboard.begin(DataPin, IRQpin);
  lcd.setCursor(0, 0);
  lcd.print("Input Message:");
  lcd.setCursor(0, 1);
}
 
void loop() {


 
 
 // Turn off the cursor:
  lcd.noCursor();
  delay(100);
  // Turn on the cursor:
  lcd.cursor();
  delay(100);
 
if (keyboard.available()) {
 

  // read the next key
    KbChars = keyboard.read();
        

   if (KbChars == PS2_ESC) {
      i=0;
      clear();
                          }
 ///////////////////// Array Display/////////////////////    
     else if (KbChars == PS2_ENTER) {
                lcd.clear();
                delay(100);
                int k=0;
                while(InputMsg[k] != '\0')
                {
                 lcd.print(InputMsg[k]);
                  k++;
                }
               }
 /////////////////////////////////////////////////////////  
   
   else
   {
      // otherwise, just print all normal characters
      lcd.print(KbChars);
    }
    InputMsg[i] = KbChars;
    i++;
    InputMsg[i] = '\0';  // terminate the string

    }
  }


void clear()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Input Message:");
  KbChars = keyboard.read();
  lcd.setCursor(0, 1);
}

Substitution Cipher code:

#include <LiquidCrystal.h>
#include <PS2Keyboard.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 13, 14, 15, 16, 17);

const int DataPin = 2;
const int IRQpin =  3;

char InputMsg[20];
static int i = 0;
char KbChars;


PS2Keyboard keyboard;
 

void setup() {
  lcd.begin(16, 2);
  delay(100);
  keyboard.begin(DataPin, IRQpin);
  lcd.setCursor(0, 0);
  lcd.print("Input Message:");
  lcd.setCursor(0, 1);
}



void loop() {

    // Turn off the cursor:
  lcd.noCursor();
  delay(100);
  // Turn on the cursor:
  lcd.cursor();
  delay(100);


 if (keyboard.available()) {
         {

          KbChars = keyboard.read();        // read one byte of input

         // A to M get converted to N to Z

         if (KbChars >= 'A' && KbChars <= 'M')

            {

            KbChars += 13;

            } /* if upper case A-M */

         // N to Z get converted to A to M

         else if (KbChars >= 'N' && KbChars <= 'Z')

            {

            KbChars -= 13;

            } /* if upper case N-Z */

         // Lower case a to m get converted to n to z

         else if (KbChars >= 'a' && KbChars <= 'm')

            {

            KbChars += 13;

            } /* if lower case a-m */

         // Lower case n to z get converted to a to m

         else if (KbChars >= 'n' && KbChars <= 'z')

            {

            KbChars -= 13;

            } /* if lower case n-z */

         lcd.write(KbChars);   // write the encrypted character back

         } // if Serial.available() > 0

 }}

Now the problem here is, both are separate programs, and what i want to do is that the data in array should be Ciphered using Substitution technique. Need to combine both programs appropriately.

Make the code that does the encryption into a function and copy it to the data collection program. Call the encryption function as and when required.

Is this the second or third thread on this topic?
I've lost count.

AWOL:
Is this the second or third thread on this topic?
I’ve lost count.

I’ve seen 5 so far.

OP: Stop opening threads, just because you don’t want to think about the next step yourself.

lg, couka

It's just too confusing to merge all these now, so I'm going to lock this one.
Please stop creating a new thread each time.