namespace net { std::string Packet_Processor::Interleave(const std::string &original) const { std::string processed(original); int i = 0; int ii = 0; for (; i < int(original.size()); i += 2) processed[i] = original[ii++]; --i; if (original.size() % 2 != 0) i -= 2; for (; i >= 0; i -= 2) processed[i] = original[ii++]; return processed; } std::string Packet_Processor::Deinterleave(const std::string &original) const { std::string processed(original); int i = 0; int ii = 0; for (; i < int(original.size()); i += 2) processed[ii++] = original[i]; --i; if (original.size() % 2 != 0) i -= 2; for (; i >= 0; i -= 2) processed[ii++] = original[i]; return processed; } std::string Packet_Processor::FlipMSB(const std::string &original) const { std::string processed(original); for (std::size_t i = 0; i < processed.size(); ++i) { processed[i] = processed[i] ^ 0x80; } return processed; } std::string Packet_Processor::SwapMultiples(const std::string &original, uint8_t multi) const { std::string processed(original); int sequence_length = 0; if (multi == 0) return processed; for (int i = 0; i <= int(processed.size()); ++i) { if (i != int(processed.size()) && ((unsigned char)processed[i]) % multi == 0) { ++sequence_length; } else { if (sequence_length > 1) { //printf("do wind: %i\n", sequence_length); std::reverse(processed.begin() + i - sequence_length, processed.begin() + i); } sequence_length = 0; } } /*if (processed != original) { printf("WINDERATED: %i\n", multi); printf("ORIG "); for (auto it = original.begin(); it != original.end(); ++it) { printf("%i ", (unsigned char)*it); } puts(""); printf("PROC "); for (auto it = processed.begin(); it != processed.end(); ++it) { printf("%i ", (unsigned char)*it); } puts(""); }*/ return processed; } } // namespace net