From 77daf867234c0a85dae328b62cb36984eca58667 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 14 Dec 2020 12:22:43 +0000 Subject: [PATCH] Decode encrypted POCSAG messages (thanks to JG1UAA for the code). --- POCSAGControl.cpp | 23 +++++++++++++++++++++-- POCSAGControl.h | 4 +++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/POCSAGControl.cpp b/POCSAGControl.cpp index 703a7ad..afa9050 100644 --- a/POCSAGControl.cpp +++ b/POCSAGControl.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2018,2019 Jonathan Naylor, G4KLX +* Copyright (C) 2018,2019,2020 Jonathan Naylor, G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -147,10 +147,23 @@ bool CPOCSAGControl::readNetwork() addAddress(functional, output->m_ric, output->m_buffer); + std::string out; switch (functional) { case FUNCTIONAL_ALPHANUMERIC: output->m_text = std::string((char*)(data + 4U), length - 4U); - LogDebug("Message to %07u, func Alphanumeric: \"%s\"", output->m_ric, output->m_text.c_str()); + switch (output->m_ric) { + case 4512U: + decodeROT1(output->m_text, 3U, out); + LogDebug("Message to %07u, func Alphanumeric: (%u) \"%s\"", output->m_ric, output->m_text.at(1U) - 0x1FU, out.c_str()); + break; + case 4520U: + decodeROT1(output->m_text, 2U, out); + LogDebug("Message to %07u, func Alphanumeric: (%u-%u) \"%s\"", output->m_ric, output->m_text.at(0U) - 0x1FU, output->m_text.at(1U) - 0x20U, out.c_str()); + break; + default: + LogDebug("Message to %07u, func Alphanumeric: \"%s\"", output->m_ric, output->m_text.c_str()); + break; + } packASCII(output->m_text, output->m_buffer); break; case FUNCTIONAL_NUMERIC: @@ -483,3 +496,9 @@ void CPOCSAGControl::enable(bool enabled) m_enabled = enabled; } + +void CPOCSAGControl::decodeROT1(const std::string& in, unsigned int start, std::string& out) const +{ + for (size_t i = start; i < in.length(); i++) + out += in.at(i) - 1U; +} diff --git a/POCSAGControl.h b/POCSAGControl.h index f101ba5..7f585e8 100644 --- a/POCSAGControl.h +++ b/POCSAGControl.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2018,2019 by Jonathan Naylor G4KLX +* Copyright (C) 2018,2019,2020 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,6 +81,8 @@ private: bool openFile(); bool writeFile(const unsigned char* data); void closeFile(); + + void decodeROT1(const std::string& in, unsigned int start, std::string& out) const; }; #endif