void manipulateOutgoingPayloadData() { //Establish a counter that increments each time this method is called. Start it at 0, and increment it by 1 each time. uint8_t aesKey[16] = EXPUNGED // key. This should be kept secret. //Now let's do some bit shifting to make it not plaintext. // Zipper for (int i = 0; i < 16; i += 2) { uint8_t temp = aesKey[i]; aesKey[i] = aesKey[i + 1]; aesKey[i + 1] = temp; } for (int i = 0; i < 16; i++) { aesKey[i] = (aesKey[i] << 3) | (aesKey[i] >> 5); // Rotate left by 3 } // Now XOR the key with different things repeated. for (int i = 0; i < 16; i++) { aesKey[i] ^= 0xAB; } for (int i = 0; i < 16; i++) { aesKey[i] ^= 0xe4; } for (int i = 0; i < 16; i++) { aesKey[i] ^= 0x17; } // Replace the first character of the key with the hash of the key (mod 256) uint8_t hash = 0; for (int i = 0; i < 16; i++) { hash ^= aesKey[i]; } aesKey[0] = hash; //Print the result, and then a newline, in hex. Temporary. //std::cout << std::endl; //Hash the entire generatePayloadBytes output, and use that as reserved[1] //TRANSMITTAL_ITERATION is special, do not touch uint8_t reserved[2] = {0x00, TRANSMITTAL_ITERATION}; std::array payloadBytes = generatePayloadBytes(reserved); uint8_t hashedNumber = 0; for (int i = 0; i < BUFFER_SIZE; i++) { hashedNumber ^= payloadBytes[i]; } // Set 1nd index to hashed number payloadBytes[0] = hashedNumber;// This should output the hash of the entire payload including reserved[0] and reserved[1] which is 0 for now. // Now, ceaser cipher the payload by XORing with the aesKey in a repeating manner for (int i = 0; i < BUFFER_SIZE; i++) { payloadBytes[i] ^= aesKey[i % 16];// Modulo 16 //even if get the key out, good luck using it. Still need the whole key cause you need the hash. } // And we done. The last bit and first bit repeat, so what. // Now we are done. // Note: We will not be using AES today. The test Arduino could not handle the delinked library :< /** which would equate to: reserved[0] = 01 reserved[1] = 02 temp = 0x45 or 69 humidity = 0x3e or 62 wind speed = 0x0b or 11 air quality = 0x73 or 115 flag = 0x70 4a 66 72 44 45 56 4b 68 31 or pJfrDEVKh1 */ //txpacket is a global variable e.g. uint8_t txpacket[BUFFER_SIZE]; and will be what is ultimately sent over the air //The first byte contains the team number. The first byte must not be changed in any way so that the middleware knows which team to route the //packet to for (int i = FIRST_WRITABLE_PACKET_POSITION; i < BUFFER_SIZE; i++) { txpacket[i] = payloadBytes[i]; } //So basically, if you want to for example apply a caesar cipher to the payload, you would loop through //each byte in payloadBytes, change the byte (apply the cipher), and then assign that byte to the correct //position of txpacket. Remember that you will then need to decrypt/decode after your weather //station receives it, so you could do this in mqtt_subscriber.py on weather station //or in the POST handler in weather-backend on WWW or anywhere else, it's up to you, as long as the //plaintext weather data gets saved in the WWW db and displayed on the website }