Arduino Strings

Here is the code

#include <SPI.h>
#include <RH_RF95.h>
#include <ArduinoJson.h>
RH_RF95 rf95;
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 151, 127};
String id1 = "123abc";

int led = 8;
int x;
int send_counter = 1000;
int counter1 = 0;
StaticJsonBuffer<200> jsonBuffer;
void setup()
{ pinMode(led, OUTPUT);
  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
}
void loop()
{
  if (rf95.available())
  { uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf95.recv(buf, &len))
    {
      digitalWrite(led, HIGH);
      Serial.print("got request: ");
      //Serial.println((char*)buf);
      String str = ((char*)buf);
      Serial.println(str);
      int length_arr = str.length();
      length_arr++;
      char json[length_arr];
      str.toCharArray(json, length_arr);
      Serial.println(json);
      JsonObject& root = jsonBuffer.parseObject(json);
      if (!root.success()) {
        Serial.println("parseObject() failed");
        return;
      }
      const char* sensor = root["ID"];
      //commandChar = sensor.charAt(2);
      if (root["ID"] == id1) {
        if (counter1 == 0) {
          int key = df_key();
          //Serial.println(key);
          counter1 = 10;
        }
        counter1--;
        char data[] = "{ \"ID\":\"SERVER\",\"TYPE\":\"OK\" }";
        rf95.send(data, sizeof(data));
        rf95.waitPacketSent();
      }
      Serial.println("Sent a reply");
      digitalWrite(led, LOW);
      jsonBuffer.clear();
    }
    else
    {
      Serial.println("recv failed");
    }
  }
}

int df_key() {
  //JsonObject& root = jsonBuffer.createObject();
  //int rund = random(1, 15);
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);
  // int  p_m = primes[rund];
  // int rund2 = random(1, 15);
  // int  g = primes[rund2];
  //int rund1 = random(1, 90);
  //String g_s = String(g);
  String g_s = "Hello";
  //int alice = rund1;
  //int to_send = (g ^ alice) % p_m;
  String x = "{\"ID\":\"SERVER\",\"TYPE\":\"KEY\",\"g\":\"" + g_s + "\",\"END\":\"END\"}";
  Serial.print(">>>>>>>>>>>");
  Serial.print(x);
  int length_arr = x.length();
  length_arr++;
  char data[length_arr];
  x.toCharArray(data, length_arr);
  rf95.send(data, sizeof(data));
  rf95.waitPacketSent();
  Serial.print("SEND : ");
  Serial.println(data);
  if (rf95.waitAvailableTimeout(3000))
  {
    // Should be a reply message for us now
    if (rf95.recv(buf, &len))
    {
      String in_str = ((char*)buf);
      Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
      Serial.print(in_str);
    }
    jsonBuffer.clear();
  }
  int to_send = 10;
  return to_send;
}