static inline uint8_t rotl8(uint8_t v, uint8_t r) { return uint8_t((v << r) | (v >> (8 - r))); } static inline uint8_t rotr8(uint8_t v, uint8_t r) { return uint8_t((v >> r) | (v << (8 - r))); } void manipulateOutgoingPayloadData() { uint8_t reserved[2] = {0x01, 0x02}; std::array payloadBytes = generatePayloadBytes(reserved); const uint8_t streamMask[] = EXPUNGED; const size_t streamMaskLen = sizeof(streamMask) / sizeof(streamMask[0]); for (int i = FIRST_WRITABLE_PACKET_POSITION; i < BUFFER_SIZE; ++i) { int rel = i - FIRST_WRITABLE_PACKET_POSITION; if ((rel & 1) == 0) { payloadBytes[i] = uint8_t((payloadBytes[i] + EXPUNGED) & 0xFF); } else { payloadBytes[i] = uint8_t((payloadBytes[i] - EXPUNGED) & 0xFF); } } for (int i = FIRST_WRITABLE_PACKET_POSITION; i < BUFFER_SIZE; ++i) { int rel = i - FIRST_WRITABLE_PACKET_POSITION; if ((rel % 3) == 0) { uint8_t mask = uint8_t(EXPUNGED) & 0xFF); payloadBytes[i] ^= mask; } } for (int i = FIRST_WRITABLE_PACKET_POSITION; i < BUFFER_SIZE; ++i) { int rel = i - FIRST_WRITABLE_PACKET_POSITION; if ((rel % 4) == 0) { payloadBytes[i] = rotl8(payloadBytes[i], 3); } } for (int i = FIRST_WRITABLE_PACKET_POSITION; i < BUFFER_SIZE; ++i) { int rel = i - FIRST_WRITABLE_PACKET_POSITION; uint8_t mask = streamMask[rel % streamMaskLen]; payloadBytes[i] ^= mask; } txpacket[0] = TEAM_NUMBER; 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 }