Перейти к основному содержимому
claw
am
tools
Инструменты
Документы
Daoark
EN
Главная
Главная
/
Verschlüsselung & Codierung
›
Главная
manifest.json
90) return c; // 步进(在输入前) positions = step(positions, rotors); var ring = [0, 0, 0]; // 简化:ring setting = 0 var r0 = ROTORS[rotors[0]], r1 = ROTORS[rotors[1]], r2 = ROTORS[rotors[2]]; var x = c; x = forward(x, r2, positions[2], ring[2]); x = forward(x, r1, positions[1], ring[1]); x = forward(x, r0, positions[0], ring[0]); var ref = REFLECTORS[reflector]; x = ref.charCodeAt(x - 65) - 65 + 65; x = backward(x, r0, positions[0], ring[0]); x = backward(x, r1, positions[1], ring[1]); x = backward(x, r2, positions[2], ring[2]); return x; } function process(text, rotorIds, initPos, reflector) { text = text.toUpperCase().replace(/[^A-Z]/g, ''); var pos = initPos.slice(); var out = ''; for (var i = 0; i < text.length; i++) { out += String.fromCharCode(encryptChar(text.charCodeAt(i), pos, rotorIds, reflector)); } return out; } function doProcess() { try { var textA = getVal('text-a'); if (!textA) { showError('请输入'); return; } var rotors = getVal('rotors').trim().split(/[\s,]+/); if (rotors.length !== 3 || !ROTORS[rotors[0]] || !ROTORS[rotors[1]] || !ROTORS[rotors[2]]) { showError('转子必须是 1-5 之间的 3 个数字'); return; } var posStr = getVal('positions').trim().toUpperCase().split(/[\s,]+/); if (posStr.length !== 3) { showError('位置必须 3 个 A-Z'); return; } var positions = posStr.map(function(p) { return p.charCodeAt(0) - 65; }); var reflector = getVal('reflector'); if (!REFLECTORS[reflector]) { showError('反射器 B 或 C'); return; } var out = process(textA, rotors, positions, reflector); showResult(out, '转子: ' + rotors.join(',') + ', 位置: ' + posStr.join(',') + ', 反射器: ' + reflector); } catch (e) { showError('处理失败: ' + (e.message || e)); } } $('btn-main').addEventListener('click', function(e) { e.preventDefault(); doProcess(); }); $('btn-clear').addEventListener('click', function() { var inputs = document.querySelectorAll('input,textarea,select'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].tagName === 'SELECT') inputs[i].selectedIndex = 0; else inputs[i].value = inputs[i].defaultValue; } var ra = $('result-area'); ra.hidden = true; ra.style.display = 'none'; var em = $('error-msg'); em.hidden = true; em.style.display = 'none'; }); })();