Dhiru Kholia 2023-12-11 09:00:21 +05:30 zatwierdzone przez GitHub
commit 6d14f02b14
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 76 dodań i 3 usunięć

Wyświetl plik

@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 199309L
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

Wyświetl plik

@ -111,6 +111,8 @@ void usage()
printf("(Note that you might have to enclose your message in quote marks if it contains spaces)\n");
}
void packtext77(const char* text, uint8_t* b77);
int main(int argc, char** argv)
{
// Expect two command-line arguments
@ -134,10 +136,15 @@ int main(int argc, char** argv)
ftx_message_rc_t rc = ftx_message_encode(&msg, NULL, message);
if (rc != FTX_MESSAGE_RC_OK)
{
// Try 'free text' encoding
if (strlen(message) <= 13)
packtext77(message, (uint8_t *)&msg.payload);
else {
printf("Cannot parse message!\n");
printf("RC = %d\n", (int)rc);
return -2;
}
}
printf("Packed data: ");
for (int j = 0; j < 10; ++j)

Wyświetl plik

@ -992,3 +992,67 @@ static int unpackgrid(uint16_t igrid4, uint8_t ir, char* extra)
return 0;
}
void packtext77(const char* text, uint8_t* b77)
{
int length = strlen(text);
// Skip leading and trailing spaces
while (*text == ' ' && *text != 0)
{
++text;
--length;
}
while (length > 0 && text[length - 1] == ' ')
{
--length;
}
// Clear the first 72 bits representing a long number
for (int i = 0; i < 9; ++i)
{
b77[i] = 0;
}
// Now express the text as base-42 number stored
// in the first 72 bits of b77
for (int j = 0; j < 13; ++j)
{
// Multiply the long integer in b77 by 42
uint16_t x = 0;
for (int i = 8; i >= 0; --i)
{
x += b77[i] * (uint16_t)42;
b77[i] = (x & 0xFF);
x >>= 8;
}
// Get the index of the current char
if (j < length)
{
int q = nchar(text[j], FT8_CHAR_TABLE_FULL);
x = (q > 0) ? q : 0;
}
else
{
x = 0;
}
// Here we double each added number in order to have the result multiplied
// by two as well, so that it's a 71 bit number left-aligned in 72 bits (9 bytes)
x <<= 1;
// Now add the number to our long number
for (int i = 8; i >= 0; --i)
{
if (x == 0)
break;
x += b77[i];
b77[i] = (x & 0xFF);
x >>= 8;
}
}
// Set n3=0 (bits 71..73) and i3=0 (bits 74..76)
b77[8] &= 0xFE;
b77[9] &= 0x00;
}