Sketch Jan16a Arduino Keyboard Client
Sketch Jan16a Arduino Keyboard Client
h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
PS2Keyboard keyboard;
#define SMS_SIZE 16
#define PLAINTEXT_SIZE (SMS_SIZE / sizeof(int))
#define CIPHERTEXT_SIZE (SMS_SIZE)
class RSA {
private:
public:
RSA();
~RSA();
void encrypt(char *plainText, char *chipherText, int *publicKey);
void decrypt(char *plainText, char *cipherText, int *privateKey);
bool compare(char *arr1, char *arr2, int len);
};
RSA rsa;
String esp_voice,esp_data;
void setup() {
keyboard.begin(DataPin, IRQpin, PS2Keymap_US);
Serial.begin(115200);
mySerial.begin(115200);
lcd.begin(16, 2);
lcd.clear();
get_prime_no();
create_keys();
}
void create_keys(){
q = key_data_int;
n = p * q;
phi_n = ( p - 1) * (q - 1);
for (int i = 1; i <= phi_n; i++) {
if (checkprime(i)) {
int gcd_value = gcd(phi_n,i);
if(gcd_value == 1){
e = i;
break;
}
}
}
Serial.print("Public Key ( e, n ) =
(");Serial.print(e);Serial.print(",");Serial.print(n);Serial.println(")");
d = modInverse(e,phi_n);
Serial.print("Private Key ( d, n ) =
(");Serial.print(d);Serial.print(",");Serial.print(n);Serial.println(")");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Note Private Key");
lcd.setCursor(0,1);
lcd.print("d = ");
lcd.print(d);
lcd.print(",");
lcd.print("n = ");
lcd.print(n);
delay(5000);
}
int modInverse(int e, int m){
e = e % m;
for (int x=1;x<m;x++){
if ((e * x) % m == 1)
return x;
}
return 1;
}
bool checkprime(int n)
{
int flag = 0;
for (int i = 2; i <= n / 2; ++i) {
// condition for non-prime
if (n % i == 0) {
flag = 1;
break;
}
}
if (n == 1) {
return false;
}
else {
if (flag == 0) {
return true;
}
else {
return false;
}
}
}
for(int i=0;i<PLAINTEXT_SIZE;i++){
msg[i] = NULL;
}
for(int i=0;i<mesg.length();i++){
msg[i] = mesg[i];
}
Serial.print("Encrypted Message:");
rsa.encrypt(msg, cipher_msg, tx_publicKey);
for(int i = 0; i < CIPHERTEXT_SIZE; i++){
Serial.write(cipher_msg[i]);
mySerial.print(cipher_msg[i]);
}
mySerial.print('#');
delay(100);
Serial.println();
}
void decrypt_message(){
char cipher[CIPHERTEXT_SIZE];
char plain[PLAINTEXT_SIZE];
memset(cipher, 0, CIPHERTEXT_SIZE);
memset(plain, 0, PLAINTEXT_SIZE);
for(int i=0;i<CIPHERTEXT_SIZE;i++)
cipher[i]= cipher_msg[i];
Serial.print("Decrypted Message:");
rsa.decrypt(plain, cipher, tx_privateKey);
Serial.println(plain);
}
void loop() {
get_message();
}
RSA::RSA()
{
RSA::~RSA()
{
}
void RSA::encrypt(char *plainText, char *cipherText, int *publicKey)
{
long m = 1;
int n = publicKey[0];
int e = publicKey[1];
int ctr = 0;
ctr = i * sizeof(int);
m = 1;
}
}
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(D5, D6); // RX, TX
byte ledPin = 2;
char ssid[] = "embedded"; // SSID of your home WiFi
char pass[] = "embedded123"; // password of your home WiFi
void setup() {
Serial.begin(115200); // only for debug
mySerial.begin(115200);
WiFi.begin(ssid, pass); // connects to the WiFi router
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("Connected to wifi");
Serial.print("Status: "); Serial.println(WiFi.status()); // Network parameters
Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
Serial.print("SSID: "); Serial.println(WiFi.SSID());
Serial.print("Signal: "); Serial.println(WiFi.RSSI());
pinMode(ledPin, OUTPUT);
}
String voice;
String data ="hello";
void loop () {
serialEvent();