+#define MAX_UL_TYPES 18
+uint32_t UL_TYPES_ARRAY[MAX_UL_TYPES] = {
+ UNKNOWN, UL, UL_C,
+ UL_EV1_48, UL_EV1_128, NTAG,
+ NTAG_203, NTAG_210, NTAG_212,
+ NTAG_213, NTAG_215, NTAG_216,
+ MY_D, MY_D_NFC, MY_D_MOVE,
+ MY_D_MOVE_NFC, MY_D_MOVE_LEAN, FUDAN_UL};
+
+uint8_t UL_MEMORY_ARRAY[MAX_UL_TYPES] = {
+ MAX_UL_BLOCKS, MAX_UL_BLOCKS, MAX_ULC_BLOCKS,
+ MAX_ULEV1a_BLOCKS, MAX_ULEV1b_BLOCKS, MAX_NTAG_203,
+ MAX_NTAG_203, MAX_NTAG_210, MAX_NTAG_212,
+ MAX_NTAG_213, MAX_NTAG_215, MAX_NTAG_216,
+ MAX_UL_BLOCKS, MAX_MY_D_NFC, MAX_MY_D_MOVE,
+ MAX_MY_D_MOVE, MAX_MY_D_MOVE_LEAN, MAX_UL_BLOCKS};
+
+// Certain pwd generation algo nickname A.
+uint32_t ul_ev1_pwdgenA(uint8_t* uid) {
+
+ uint8_t pos = (uid[3] ^ uid[4] ^ uid[5] ^ uid[6]) % 32;
+
+ uint32_t xortable[] = {
+ 0x4f2711c1, 0x07D7BB83, 0x9636EF07, 0xB5F4460E, 0xF271141C, 0x7D7BB038, 0x636EF871, 0x5F4468E3,
+ 0x271149C7, 0xD7BB0B8F, 0x36EF8F1E, 0xF446863D, 0x7114947A, 0x7BB0B0F5, 0x6EF8F9EB, 0x44686BD7,
+ 0x11494fAF, 0xBB0B075F, 0xEF8F96BE, 0x4686B57C, 0x1494F2F9, 0xB0B07DF3, 0xF8F963E6, 0x686B5FCC,
+ 0x494F2799, 0x0B07D733, 0x8F963667, 0x86B5F4CE, 0x94F2719C, 0xB07D7B38, 0xF9636E70, 0x6B5F44E0
+ };
+
+ uint8_t entry[] = {0x00,0x00,0x00,0x00};
+ uint8_t pwd[] = {0x00,0x00,0x00,0x00};
+
+ num_to_bytes( xortable[pos], 4, entry);
+
+ pwd[0] = entry[0] ^ uid[1] ^ uid[2] ^ uid[3];
+ pwd[1] = entry[1] ^ uid[0] ^ uid[2] ^ uid[4];
+ pwd[2] = entry[2] ^ uid[0] ^ uid[1] ^ uid[5];
+ pwd[3] = entry[3] ^ uid[6];
+
+ return (uint32_t)bytes_to_num(pwd, 4);
+}
+
+// Certain pwd generation algo nickname B. (very simple)
+uint32_t ul_ev1_pwdgenB(uint8_t* uid) {
+
+ uint8_t pwd[] = {0x00,0x00,0x00,0x00};
+
+ pwd[0] = uid[1] ^ uid[3] ^ 0xAA;
+ pwd[1] = uid[2] ^ uid[4] ^ 0x55;
+ pwd[2] = uid[3] ^ uid[5] ^ 0xAA;
+ pwd[3] = uid[4] ^ uid[6] ^ 0x55;
+ return (uint32_t)bytes_to_num(pwd, 4);
+}
+
+void ul_ev1_pwdgen_selftest(){
+
+ uint8_t uid1[] = {0x04,0x11,0x12,0x11,0x12,0x11,0x10};
+ uint32_t pwd1 = ul_ev1_pwdgenA(uid1);
+ PrintAndLog("UID | %s | %08X | %s", sprint_hex(uid1,7), pwd1, (pwd1 == 0x8432EB17)?"OK":"->8432EB17<-");
+
+ uint8_t uid2[] = {0x04,0x1f,0x98,0xea,0x1e,0x3e,0x81};
+ uint32_t pwd2 = ul_ev1_pwdgenB(uid2);
+ PrintAndLog("UID | %s | %08X | %s", sprint_hex(uid2,7), pwd2, (pwd2 == 0x5fd37eca)?"OK":"->5fd37eca<--");
+ return;
+}
+