This commit is contained in:
Connor 2018-06-03 03:36:00 -07:00 committed by GitHub
parent aab2829c9c
commit f4c682bbea

View File

@ -15,6 +15,9 @@ typedef uint64_t u64;
#define LEN(a) (sizeof(a) / sizeofel(a))
const char *lut[] = {
// characters within the same string are considered the same.
// that means the number of choices for a single character
// goes down from 36 to 28.
"N", "P", "Q", "R",
"T", "W", "X", "Y",
"17I", "2Z", "5S", "8B",
@ -114,6 +117,7 @@ int decode_data(code_t *code) {
if (!check_ranges(code)) return 0;
// TODO: refactor so this isn't repeated in encode_data.
const u32 neg1 = (u32)-1;
if (code->data[2] == neg1 || code->data[2] != code->data[4]); else return 0;
if (code->data[1] < 7 || (code->data[2] != neg1 && code->data[4] != neg1)); else return 0;
@ -197,20 +201,41 @@ int bruteforce() { // with a fixed seed, this is useful for testing.
int main(int argc, char **argv) {
if (argc == 1) {
// self-test.
if (!validate_entry("48HWOR482")) return -1;
if (!validate_entry("5G3LTQ5GN")) return -1;
if (!validate_entry("A3W5KQA3C")) return -1;
if (!validate_entry("ARM6JQARU")) return -1;
if (!validate_entry("E8ULJRE8M")) return -1;
if (!validate_entry("J6M9PQJ6U")) return -1;
if (!validate_entry("LA98JRLAR")) return -1;
if (!validate_entry("M1C2YQM1W")) return -1;
if (!validate_entry("MM55MQMMJ")) return -1;
if (!validate_entry("N24K8QN2P")) return -1;
if (!validate_entry("OF9XFQOFR")) return -1;
if (!validate_entry("UOUFMPUOM")) return -1;
if (!validate_entry("V2UFMPUZM")) return -1;
// self-test with codes known before this program was written.
#define TEST(entry) if (!validate_entry(entry)) return -1
TEST("48HWOR482");
TEST("5G3LTQ5GN");
//TEST("5PURGR5PM");
//TEST("6PJEGRGP5");
//TEST("8GYUHR86F");
TEST("A3W5KQA3C");
TEST("ARM6JQARU");
TEST("E880MPE8K");
TEST("E8ULJRE8M");
TEST("EPJEGREP5");
TEST("GH4KNQGHP");
TEST("H6L3MPH60");
TEST("HH4KNQHHP");
TEST("J6M9PQJ6U");
TEST("JEP8YQJE4");
TEST("LA98JRLAR");
TEST("LQM1MPLQU");
TEST("LTHWYQLT2");
TEST("M1C2YQM1W");
TEST("MM55MQMMJ");
TEST("N24K8QN2P");
TEST("OF9XFQOFR");
TEST("P4K6GRP48");
TEST("TE6WARTEQ");
TEST("TQJEGRTQ5");
TEST("UOUFMPUOM");
TEST("V2UFMPUZM");
TEST("W2HEGRW22");
TEST("WQJEGRWQ5");
TEST("WRWQARWRC");
TEST("YQJEGRYQ5");
//TEST("ZKZLZKNNR");
#undef TEST
return 0;
}