Created
September 21, 2024 01:05
-
-
Save noproto/8102f8f32546564cd674256e62ff76ea to your computer and use it in GitHub Desktop.
Generate seednt16, original research by doegox
This file contains 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 <stdbool.h> | |
#include <assert.h> | |
#include <stdio.h> | |
static uint16_t prev_lfsr16(uint16_t x) { | |
return ((x << 1 | x >> 15) & 0xffff) ^ ((x >> 1 ^ x >> 2 ^ x >> 4) & 0x100); | |
} | |
static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) { | |
static const uint8_t a[] = {0, 8, 9, 4, 6, 11, 1, 15, 12, 5, 2, 13, 10, 14, 3, 7}; | |
static const uint8_t b[] = {0, 13, 1, 14, 4, 10, 15, 7, 5, 3, 8, 6, 9, 2, 12, 11}; | |
uint16_t nt = nt32 >> 16; | |
for (int i = 0; i < 14; i++) { | |
nt = prev_lfsr16(nt); | |
} | |
bool odd = true; | |
for (int i = 0; i < 6 * 8; i += 8) { | |
if (odd) { | |
nt ^= a[(key >> i) & 0xF] | (b[(key >> (i + 4)) & 0xF] << 4); | |
} else { | |
nt ^= b[(key >> i) & 0xF] | (a[(key >> (i + 4)) & 0xF] << 4); | |
} | |
odd = !odd; | |
for (int j = 0; j < 8 + i / 8; j++) { | |
nt = prev_lfsr16(nt); | |
} | |
} | |
return nt; | |
} | |
int main() { | |
// Test compute_seednt16_nt32 | |
uint32_t nt32 = 0x12345678; | |
uint64_t key = 0x0123456789AB; | |
uint16_t result = compute_seednt16_nt32(nt32, key); | |
printf("compute_seednt16_nt32 result: 0x%04X\n", result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment