#include "compression.h" using math::wide_integer::uint512_t; uint512_t decodeBase(int b, const char *str); const char* digits = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-./?@"; // This function is from aprs434.github.io, // MIT License, Copyright (c) 2022 Serge Y. Stroobandt, ON4AA uint32_t encodeCallsign(const char *callsign) { // Encode CCCC according to aprs434.github.io/code/codec.cpp const int b = 37; uint32_t result; uint32_t weight; int i, j, k, ch; result = 0, weight = 1; for (i = j = strlen(callsign); i > 0; i--) { // iterate over input string ch = toupper(callsign[i-1]); for (k = 0; k < strlen(digits); k++) { // lookup char index if (digits[k] == ch) { break; } } if (k == strlen(digits)) // ignore if ch not found in digits continue; result = result + ((k) * weight); weight = weight * b; } return result; // result can be pow(42,51)! } // This function is from ESP32 lora.tracker, // MIT License, Copyright (c) 2020 Peter Buchegger void ax25_base91enc(char *s, uint8_t n, uint32_t v) { /* Creates a Base-91 representation of the value in v in the string * pointed to by s, n-characters long. String length should be n+1. */ for (s += n, *s = '\0'; n; n--) { *(--s) = v % 91 + 33; v /= 91; } } static void strrev(char s[]) { int length = strlen(s) ; int c, i, j; for (i = 0, j = length - 1; i < j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } } inline void assert(bool cond) { while (!cond) {} } static uint8_t bytes[100]; uint512_t decodeBase(int b, const char* str) { // base b, str 64 bytes max '\0' terminated uint512_t result; uint512_t weight; int i, j, k, ch; assert(b <= strlen(digits)); assert(b > 1); result = 0, weight = 1; for (i = j = strlen(str); i > 0; i--) // iterate over input string { ch=toupper(str[i-1]); for (k = 0; k < strlen(digits); k++) { //lookup char index if (digits[k] == ch) { break; } } if (k == strlen(digits)) // ignore if ch not found in digits continue; result = result + ((k) * weight); weight = weight * b; } return result; // result can be pow(42,51)! } uint512_t encodetttt(const char *s) { return decodeBase(42, s); }