<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SPRD Unlock Code Calculator</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
            min-height: 50vh;
            display: flex;
            align-items: center;
        }
        .container {
            max-width: 600px;
            margin: auto;
        }
        .calculator-box {
            background: white;
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="calculator-box">
            <h5 class="text-center mb-2">HISENSE ALL | ITEL | MOBICELL | AZUMI | TECNO | VORTEX | SPD | MTK | UNLOCK CALC</h5>
            <hr>
            <br/>
            <div class="mb-3">
                <center><label for="imeiInput" class="form-label">Enter IMEI Number:</label></center>
                <input type="text" class="form-control" id="imeiInput" placeholder="15-digit IMEI">
            </div>
            <button class="btn btn-primary w-100 mb-3" onclick="calculateNCK()"><b>Calculate NCK</b></button>
            <b><div id="result" class="alert alert-info text-center" style="display: none;"></div></b>
            <div id="error" class="alert alert-danger text-center" style="display: none;"></div>
			<center><b>Created by DublinGSM</b></center>
        </div>
    </div>
    
    <script>
        function calculateNCK() {
            const imei = document.getElementById('imeiInput').value.trim();
            const resultDiv = document.getElementById('result');
            const errorDiv = document.getElementById('error');
            
            // Reset displays
            resultDiv.style.display = 'none';
            errorDiv.style.display = 'none';

            // Validation
            if (!imei || imei.length !== 15 || isNaN(imei)) {
                errorDiv.textContent = "Please enter a valid 15-digit IMEI number";
                errorDiv.style.display = 'block';
                return;
            }

            // Algorithm implementation
            try {
                let nck = '';
                const firstDigit = imei[0];
                
                // Process first 14 digits as 7 pairs
                for (let i = 0; i < 14; i += 2) {
                    const pair = imei.substr(i, 2);
                    const sum = parseInt(pair[0]) + parseInt(pair[1]);
                    nck += sum % 10; // Get last digit of sum
                }
                
                // Add first IMEI digit as last NCK digit
                nck += firstDigit;

                // Display result
                resultDiv.textContent = `NCK Code: ${nck}`;
                resultDiv.style.display = 'block';
            } catch (error) {
                errorDiv.textContent = "Error calculating NCK. Please check the IMEI.";
                errorDiv.style.display = 'block';
            }
        }
    </script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>