| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>YubiKey NFC-ID Calculator</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- max-width: 600px;
- margin: 50px auto;
- padding: 20px;
- }
- .container {
- border: 1px solid #ccc;
- padding: 20px;
- border-radius: 5px;
- }
- label {
- display: block;
- margin-bottom: 10px;
- font-weight: bold;
- }
- input {
- width: 100%;
- padding: 8px;
- margin-bottom: 15px;
- box-sizing: border-box;
- font-size: 14px;
- }
- button {
- padding: 10px 20px;
- background-color: #007bff;
- color: white;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- }
- button:hover {
- background-color: #0056b3;
- }
- .output {
- margin-top: 20px;
- padding: 15px;
- background-color: #f5f5f5;
- border-radius: 4px;
- font-family: monospace;
- }
- .output-label {
- font-weight: bold;
- margin-bottom: 5px;
- }
- .output-value {
- font-size: 16px;
- word-break: break-all;
- }
- .error {
- color: red;
- margin-top: 10px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>YubiKey NFC-ID Calculator</h1>
- <p>Enter a YubiKey serial number (decimal) to calculate its NFC-ID (v5.3.0+ format).</p>
-
- <label for="serialNumber">Serial Number (Decimal):</label>
- <input type="number" id="serialNumber" placeholder="e.g., 23852733" min="0" step="1">
-
- <button onclick="calculateNFCID()">Calculate NFC-ID</button>
-
- <div id="output"></div>
- <div id="error" class="error"></div>
- </div>
- <script>
- function calculateNFCID() {
- const serialInput = document.getElementById('serialNumber').value;
- const errorDiv = document.getElementById('error');
- const outputDiv = document.getElementById('output');
-
- // Clear previous output
- errorDiv.textContent = '';
- outputDiv.innerHTML = '';
-
- // Validate input
- if (!serialInput || serialInput.trim() === '') {
- errorDiv.textContent = 'Please enter a serial number.';
- return;
- }
-
- const serialNumber = parseInt(serialInput, 10);
-
- if (isNaN(serialNumber) || serialNumber < 0) {
- errorDiv.textContent = 'Please enter a valid positive number.';
- return;
- }
-
- // Convert to hex and pad to 8 characters (4 bytes)
- let hexString = serialNumber.toString(16).toLowerCase();
- hexString = hexString.padStart(8, '0');
-
- // Extract the 4 bytes
- // serial_0 is most significant (leftmost), serial_3 is least significant (rightmost)
- const serial_0 = hexString.substring(0, 2);
- const serial_1 = hexString.substring(2, 4);
- const serial_2 = hexString.substring(4, 6);
- const serial_3 = hexString.substring(6, 8);
-
- // Calculate NFC-ID according to formula:
- // 0x88 0x27 serial_3 serial_2 serial_1 serial_0 serial_2 serial_3
- // Based on user example, they want: 27 serial_3 serial_2 serial_1 serial_0 serial_2 serial_3
- const nfcId = '27' + serial_3 + serial_2 + serial_1 + serial_0 + serial_2 + serial_3;
-
- // Display results
- outputDiv.innerHTML = `
- <div class="output">
- <div class="output-label">Serial Number (Hex):</div>
- <div class="output-value">${hexString}</div>
- </div>
- <div class="output">
- <div class="output-label">NFC-ID:</div>
- <div class="output-value">${nfcId}</div>
- </div>
- `;
- }
-
- // Allow Enter key to trigger calculation
- document.getElementById('serialNumber').addEventListener('keypress', function(e) {
- if (e.key === 'Enter') {
- calculateNFCID();
- }
- });
- </script>
- </body>
- </html>
|