Esempio n. 1
0
        public override void codificar()
        {
            cargarDatos();
            Dto.TipoTraduccion = "Codificacion";
            int    val     = Int32.Parse(pValor);
            string res     = "";
            int    primero = val / 10;
            int    segundo = val % 10;
            bool   flag    = true;

            for (int i = 0; i < pTexto.Length; i++)
            {
                if (pTexto.ElementAt(i) == ' ')
                {
                    res  = res + " ";
                    flag = true;
                }
                else
                {
                    if (flag)
                    {
                        res  = res + Alfabeto.ElementAt((Alfabeto.IndexOf(pTexto.ElementAt(i)) + primero) % Alfabeto.Length);
                        flag = false;
                    }
                    else
                    {
                        res  = res + Alfabeto.ElementAt((Alfabeto.IndexOf(pTexto.ElementAt(i)) + segundo) % Alfabeto.Length);
                        flag = true;
                    }
                }
            }
            Dto.FraseResultado = res;
        }
        public override void decodificar()
        {
            cargarDatos();
            Dto.TipoTraduccion = "Decodificacion";
            string res = "";

            string[] arregloPalabras = pTexto.Split(' ');
            for (int i = 0; i < arregloPalabras.Length; i++)
            {
                for (int j = 0; j < arregloPalabras[i].Length; j++)
                {
                    if (0 > (Alfabeto.IndexOf(arregloPalabras[i].ElementAt(j)) - 1 - (Alfabeto.IndexOf(pValor.ElementAt(j % pValor.Length)))) % Alfabeto.Length)
                    {
                        res = res + Alfabeto.ElementAt((Alfabeto.IndexOf(arregloPalabras[i].ElementAt(j)) - 1 - (Alfabeto.IndexOf(pValor.ElementAt(j % pValor.Length))) + Alfabeto.Length));
                    }
                    else
                    {
                        res = res + Alfabeto.ElementAt((Alfabeto.IndexOf(arregloPalabras[i].ElementAt(j)) - 1 - (Alfabeto.IndexOf(pValor.ElementAt(j % pValor.Length)))));
                    }
                }
                res = res + " ";
            }

            Dto.FraseResultado = res;
        }
Esempio n. 3
0
 public static Alfabeto getInstance()
 {
     if (alfabeto == null)
     {
         alfabeto = crearAlfabeto();
     }
     return(alfabeto);
 }
Esempio n. 4
0
        string convertirNumABinario(string letra)
        {
            string res         = "";
            int    numAsociado = Alfabeto.IndexOf(letra.ElementAt(0));

            while (numAsociado > 0)
            {
                if (numAsociado % 2 == 0)
                {
                    res = "0" + res;
                }
                else
                {
                    res = "1" + res;
                }
                numAsociado = (int)(numAsociado / 2);
            }
            return(ceros(res));
        }
Esempio n. 5
0
        public override void decodificar()
        {
            cargarDatos();
            Dto.TipoTraduccion = "Decodificacion";
            string[] numeros = pTexto.Split(' ');
            string   res     = "";

            for (int i = 0; i < numeros.Length; i++)
            {
                if (numeros[i] == "*")
                {
                    res = res + " ";
                }
                else
                {
                    res = res + Alfabeto.ElementAt(BinADec(numeros[i]));
                }
            }
            Dto.FraseResultado = res;
        }
Esempio n. 6
0
 public void crearAlfabeto()
 {
     alfabeto = SingletonAlfabeto.getInstance();
 }