<!
DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Cifrado Polybios</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
background: #555;
}
.content {
max-width: 500px;
margin: auto;
background: white;
padding: 10px;
}
</style>
</head>
<body>
<div class="content">
<h1 align='center'>CIFRADO POLYBIOS</h1>
<h2>Tipo de lenguaje:</h2>
<select id="cif">
<option value="1">NUMERICO</option>
<option value="2">ALFANUMERICO</option>
</select>
<h2>Mensaje: </h2>
<input type="text" id="mensaje" required><br>
<button onclick="generar(true)">CODIFICAR</button>
<button onclick="generar(false)">DECODIFICAR</button>
<script>
//letras a tomar
var abc = 'ABCDEFGHIKLMNOPQRSTUVWXYZ';
var num = '12345';
var letr = 'ABCDE';
//Constructor de letras
function Letras(letra, xl, yl, xn, yn) {
[Link] = letra;
[Link] = xl;
[Link] = yl;
[Link] = xn;
[Link] = yn;
}
//Generador de letras
var letras = [];
var cont = 0;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
letras[cont] = new Letras(abc[cont], letr[i], letr[j], num[i],
num[j]);
cont++;
}
}
[Link](letras);
//funcion principal
function generar(x) {
//Toma las variables
var mensaje = [Link]('mensaje').value;
mensaje = [Link]();
var codificado = "";
var elec = [Link]('cif').value;
if (x) {
if (elec == 1) {
alert('CODIFICACION NUMERICA');
for (i = 0; i < [Link]; i++) {
for (j = 0; j < [Link]; j++) {
if (mensaje[i] == letras[j].letra) {
codificado = codificado + letras[j].xn +
letras[j].yn + ' ';
}
}
}
} else {
alert('CODIFICACION LETRAS');
for (i = 0; i < [Link]; i++) {
for (j = 0; j < [Link]; j++) {
if (mensaje[i] == letras[j].letra) {
codificado = codificado + letras[j].xl +
letras[j].yl + ' ';
}
}
}
}
} else {
if (elec == 1 ) {
alert('DECODIFICACION NUMERICA');
for (i = 0; i < [Link]; i++) {
if (mensaje[i] == ' ') {
codificado = codificado + ' ';
} else {
for (j = 0; j < [Link]; j++) {
if (mensaje[i] == letras[j].xn && mensaje[i +
1] == letras[j].yn) {
codificado = codificado + letras[j].letra;
i++;
}
}
}
}
} else {
alert('DECODIFICACION LETRAS');
for (i = 0; i < [Link]; i++) {
if (mensaje[i] == ' ') {
codificado = codificado + ' ';
} else {
for (j = 0; j < [Link]; j++) {
if (mensaje[i] == letras[j].xl && mensaje[i +
1] == letras[j].yl) {
codificado = codificado + letras[j].letra;
i++;
}
}
}
}
}
}
impresion(codificado);
}
function impresion(x) {
[Link]("Mensaje").innerHTML = "<h4>" + x +
"</h4>";
}
</script>
<h2>Su mensaje es:</h2>
<div id="Mensaje" align='center'></div>
</div>
</body>
</html>