Encrypt the latitude and longitude from GPS module on UNO board

//transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "photon256.h"
#include "photon-beetle.h"
#include "aead.h"
#include "util.h"

TinyGPSPlus gps;
SoftwareSerial ss(2, 3);
RF24 radio(8, 7);

struct pengirimGPS{
  float latitude;
  float longitude;
};
pengirimGPS gpsData;

struct cipher{
  unsigned char cipher1;
  unsigned char cipher2;  
};
cipher ctx;

struct plain{
  unsigned char plain1;
  unsigned char plain2;
};
plain ptx;

int enkripsi
    (unsigned char *c, long long *clen,
     const unsigned char *m, long long mlen,
     const unsigned char *ad, long long adlen,
     const unsigned char *nsec,
     const unsigned char *npub,
     const unsigned char *k)
{
    return photon_beetle_128_aead_encrypt
        (c, clen, m, mlen, ad, adlen, nsec, npub, k);
}

static unsigned char const key[16] = {
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
static unsigned char const nonce[16] = {
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
static unsigned char const ad[16] = {
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};

void printHex(const unsigned char *data, int size) {
  static unsigned char const hex[] = "0123456789abcdef";
  while (size > 0) {
      int b = *data++;
      Serial.print(hex[(b >> 4) & 0x0F]);
      Serial.print(hex[b & 0x0F]);
      --size;
  }
  Serial.println();
}

void setup() {
  Serial.begin(9600);
  ss.begin(9600);
  
  Serial.println("Setting up radio");
  //  Setup transmitter radio
  radio.begin();
  radio.openWritingPipe(0xF0F0F0F0E1LL); //untuk 1 sensor
  radio.setChannel(0x76);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.stopListening();
  radio.enableDynamicPayloads();
  radio.powerUp();
  Serial.println("Starting to send");
}

void GPS(){
  if (gps.location.isValid()){
    gpsData.longitude = gps.location.lng();
    ptx.plain1 = gpsData.longitude;        
    //dtostrf(gpsData.longitude, 6, 3, ptx.plain1);
  
    gpsData.latitude = gps.location.lat();
    ptx.plain2 = gpsData.latitude;
    //dtostrf(gpsData.latitude, 6, 3, ptx.plain2);

  } else{
    gpsData.longitude = 0.0;
    gpsData.latitude = 0.0;
  }
  delay(1000);
}

void enkrip_GPS(){
  enkripsi(ctx.cipher1, (6+16), ptx.plain1, 6, ad, 16, 16, nonce, key);
  enkripsi(ctx.cipher2, (6+16), ptx.plain2, 6, ad, 16, 16, nonce, key);  
}

void loop() {
  while (ss.available() > 0){
    if (gps.encode(ss.read())){
      GPS();
      enkrip_GPS();
      //radio.write(&gpsData, 6);      
      radio.write(&ctx, 6+16);
      
      Serial.print("plaintext data :");
      Serial.println(ptx.plain1, 6); Serial.println(ptx.plain2, 6);
      //Serial.println(gpsData.longitude,6); Serial.println(gpsData.latitude,6);
      
      Serial.println();
      Serial.println("encrypted data :");
      printHex(ctx.cipher1, 6 + 16); printHex(ctx.cipher2, 6 + 16);
    }
  }
}

This is the library that i used:

when I uploading the .ino , the plain version of longitude and latitude, and ciphertext version of longitude and latitude is not show in serial monitor, but the compiling process is not error. what should i do? Thanks

the library that i used:

the library that i used:

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

Please edit your post to add code tags. See the "How to get the best out of the forum" post for instructions.

What was the reason for commenting out the dtostrf() step, and what do you expect to happen here?

    gpsData.longitude = gps.location.lng();
    ptx.plain1 = gpsData.longitude;        
    //dtostrf(gpsData.longitude, 6, 3, ptx.plain1);
  

it's the alternative that i used convert the float/double data type longitude and latitude into unsigned char ptx.plain1/2. because the photon-bettle encryption is using unsigned char type data for input plaintext, key, and the others

What do you think happens when you copy a binary floating point value into a single character?

Better: what actually happens?

I want to explain my project. I build the radio (RF24) communication between 2 arduino uno that is transmitting GPS data from GPS module on transmitter-side. on that communication, i want the GPS data (longitude and latitude) is enrypted using photon-bettle algorithm. So, on the transmitter-side is get GPS data and encrypting that, and the receiver-side is receiving message and decrypting the message. I hope the result of decrypting message is the same as the GPS data on the transmitter-side.

What's the purpose of encrypting it?

and the problem is the library of photon-bettle is using unsigned char data type for plaintext, key, nonce, ciphertext. But the GPS data message is using float/double data type, so when I want to encrypt using photon-bettle, the GPS data is must be convert to unsigned char.

the goal is confidentiality message, so nobody knows the original message

Then use dtostrf() to do that.

This struct consists of two, single byte members, and cannot contain useful location information.

struct plain{
  unsigned char plain1;
  unsigned char plain2;
};
plain ptx;

Perhaps you meant something like the following. Use dtostrf() to populate the plain text array.

struct plain{
  unsigned char plain1[16];
  unsigned char plain2[16];
};
plain ptx;

What makes you think anyone cares? Or that they will be within RF24 range with a receiver configured to the correct address and software that knows the data format?