eqr 1.9.45

Encode text into svg/png/jpg/terminal-format QR codes with optional logo
// crc16.c - CRC16 with start 0xFFFF and POLYNOMIAL 0x1021 as used in PromptPay

#include <stdint.h>
#include <stdio.h>
#include <string.h>

#define CRC_START 0xFFFF
#define CRC_POLYNOMIAL 0x1021

uint16_t crc16(const uint8_t *data) {
	uint16_t crc = CRC_START;
	uint32_t len = strlen(data);
	while (len--) {
		crc = crc ^ ((uint16_t) (*data++ << 8));
		for (int i = 0; i < 8; i++)
			if (crc & 0x8000)
				crc = (crc << 1) ^ CRC_POLYNOMIAL;
			else
				crc = crc << 1;
	}
	return crc;
}

int main(int argc, char *argv[]) {
	uint8_t *data = "";
	if (argc > 1)
		data = argv[1];
	printf("%04X '%s'\n", crc16(data), data);
}