作为程序员,没有合适的工具,就得手搓一个,PC端,移动端均可适用。废话不多说,直接上代码。
HTML:
<div class="calculator"><div class="form-group"><label for="len">密码长度:</label> <input id="len" min="1" type="number" placeholder="例如: 8"></div><div class="form-group"><label for="cha">字符集数量:</label> <input id="cha" min="1" type="number" placeholder="例如: 26 或 62"></div><button onclick="calculateCombinations()">计算组合</button><div id="result" class="result"></div></div>
JS:
function calculateCombinations() {
const lengthInput = document.getElementById('len');
const charsetInput = document.getElementById('cha');
const resultDiv = document.getElementById('result');
const length = parseInt(lengthInput.value);
const charset = parseInt(charsetInput.value);
if (isNaN(length) || length <= 0 || isNaN(charset) || charset <= 0) {
resultDiv.textContent = "请输入有效的密码长度和字符集数量!";
return;
}
// 密码组合数量 = 字符集数量 ^ 密码长度
const combinations = Math.pow(charset, length);
resultDiv.textContent = `可能的密码组合: ${combinations.toLocaleString()} 种`;
}
CSS:
.calculator {
width: 100%;
background-color: #333;
color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
label {
display: block;
margin-bottom: 10px;
font-size: 16px;
}
input, select {
width: 100%!important;
padding: 10px!important;
margin-bottom: 20px;
color: #000000;
border-radius: 5px;
border: 1px solid #555;
font-size: 16px!important;
background-color: #ffffff!important;
}
button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
display: block;
margin: 0px;
margin-bottom: 20px;
margin-left: 0px!important;
}
button:hover {
background-color: orange;
}
.result {
margin-top: 20px;
text-align: center;
}
option {
background-color: #ffffff;
}
p {
font-size: 18px;
margin-top: 5px!important;
}