Created
November 30, 2023 18:42
-
-
Save bettse/79386bf74c402ed1b5906b9161880c64 to your computer and use it in GitHub Desktop.
ld_pwdgen.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
#if defined(__APPLE__) | |
#include <libkern/OSByteOrder.h> | |
#define bswap_16(x) OSSwapInt16(x) | |
#define bswap_32(x) OSSwapInt32(x) | |
#else | |
#include <byteswap.h> | |
#endif | |
bool debug = false; | |
#define rotr32(s, n) (((n) >> s) | ((n) << (32 - s))) | |
uint32_t sub_1440(uint64_t uid) { | |
uint8_t base[] = { | |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x28, | |
0x63, 0x29, 0x20, 0x43, 0x6f, 0x70, 0x79, 0x72, | |
0x69, 0x67, 0x68, 0x74, 0x20, 0x4c, 0x45, 0x47, | |
0x4f, 0x20, 0x32, 0x30, 0x31, 0x34, 0xaa, 0xaa}; | |
//Copy UID into structure | |
for (int i = 0; i < 7; i++) { | |
//Casting to pointer and using subtracted index because | |
//the 7 byte uid is stored in a 8 byte type in the reverse | |
//order or what I need. | |
base[i] = ((uint8_t *)&uid)[6 - i]; | |
} | |
if (debug) { | |
printf("i\tv4\tv5\tb\tv2\n"); | |
} | |
uint32_t v2 = 0; | |
for (int i = 0; i < 8; i++) { | |
int v4 = rotr32(25, v2); | |
int v5 = rotr32(10, v2); | |
uint32_t b = *(uint32_t *)(base + i * 4); | |
v2 = b + v4 + v5 - v2; | |
if (debug) { | |
printf("[%d] %08x %08x %08x %08x\n", i, v4, v5, b, v2); | |
} | |
} | |
return bswap_32(v2); | |
} | |
int main(int argc, char *argv[]) { | |
if (argc != 2) { | |
printf("%s <7 byte uid in hex>\n", argv[0]); | |
return 1; | |
} | |
uint64_t uid = strtoull(argv[1], NULL, 0x10); | |
printf("uid = %014llx => %08x\n", uid, sub_1440(uid)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment