@Christoph-Hart I think I succeeded, thanks
const d = BigInt('0x' + dHex); const n = BigInt('0x' + nHex); const modulusBits = n.toString(2).length; const modulusBytes = Math.ceil(modulusBits / 8); const requiredHexLength = modulusBytes * 2; const messageBuffer = Buffer.from(machineCode); const reversedBuffer = Buffer.from(messageBuffer).reverse(); let value = BigInt('0x' + reversedBuffer.toString('hex')); let result = 0n; const modulus = n; while (value > 0n) { const remainder = value % modulus; value = value / modulus; const encryptedChunk = modExp(remainder, d, modulus); result = result * modulus + encryptedChunk; } let hexStr = result.toString(16).padStart(requiredHexLength, '0'); const finalBuffer = Buffer.from(hexStr, 'hex'); return { activationCode: finalBuffer.toString('hex') }; function modExp(base, exp, mod) { let result = 1n; base = base % mod; while (exp > 0n) { if (exp & 1n) result = (result * base) % mod; exp = exp >> 1n; base = (base * base) % mod; } return result; }