Bienvenido a Tecnohackers

Tecnohackers » Comunicaciones y Redes » Android » Software y Aplicaciones Android (Moderador: Zentraedi)
 » 

Cifrado de Cesar app - By Zentraedi (Modificado V2.0)



Autor Tema: Cifrado de Cesar app - By Zentraedi (Modificado V2.0)  (Leído 599 veces)

Desconectado Zentraedi

  • Moderator
  • Habitual
  • *****
  • Mensajes: 134
  • "El universo cantara mi canción" Nekki Basara
Cifrado de Cesar app - By Zentraedi (Modificado V2.0)
« en: Agosto 29, 2016, 06:53:06 pm »
Hola a amigos de Tecnohackers les comparto una app que arme con el famoso cifrado de cesar para poder cifrar los mensajes y textos que querramos, es algo simple y quizas viejo pero lo comparto con ustedes y espero que sea de su agrado, acepto todo tipo de criticas al respecto, saludos.

Edit: resuelto error de cierre de aplicacion si el campo de la Clave queda vacio, se añado la opcion de enviar por E-Mail los mensajes cifrados.

Capturas:






V2.0:




Codigo Xamarin.Android:
Código: You are not allowed to view links. Register or Login
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace CifradoCesar
{
    [Activity(Label = "CifradoCesar", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        static string abc = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ_-+,#$%/()¿?¡!|,.;:{}[]";
        EditText Clave, Mensaje;
        ImageButton Cifrar, Borrar, Descifrar, Enviar;
        TextView Msj;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Clave = FindViewById<EditText>(Resource.Id.editText1);
            Mensaje = FindViewById<EditText>(Resource.Id.editText2);
            Cifrar = FindViewById<ImageButton>(Resource.Id.imageButton1);
            Borrar = FindViewById<ImageButton>(Resource.Id.imageButton2);
            Descifrar = FindViewById<ImageButton>(Resource.Id.imageButton3);
            Msj = FindViewById<TextView>(Resource.Id.textView2);
            Enviar = FindViewById<ImageButton>(Resource.Id.Enviar);

            Clave.Text = "0";

         
            Cifrar.Click += delegate
            {
                if (Clave.Text.Equals(""))
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    AlertDialog error = alert.Create();
                    error.SetTitle("Error");
                    error.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                    error.SetMessage("Debes colocar la clave para Cifrar");
                    error.SetButton("OK", (w, a) => { });
                    error.Show();
                }
                else  {
                    int clave = Convert.ToInt32(Clave.Text);

                    if (clave > 76 || clave == 0)
                    {
                        AlertDialog.Builder alert = new AlertDialog.Builder(this);
                        AlertDialog error = alert.Create();
                        error.SetTitle("Error");
                        error.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                        error.SetMessage("La clave no es un numero valido, la clave debe ser un numero de 1 a 76");
                        error.SetButton("OK", (w, a) => { });
                        error.Show();
                    }
               
                else if (Mensaje.Text == "")
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    AlertDialog error = alert.Create();
                    error.SetTitle("Error");
                    error.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                    error.SetMessage("No hay mensaje para cifrar, escribe uno");
                    error.SetButton("OK", (w, a) => { });
                    error.Show();
                }
                else
                {
                   
                    string MsjCifrado = cifrar(Mensaje.Text, clave);
                    Mensaje.Text = MsjCifrado;
                    Msj.Text = "Mensaje Cifrado:";
                }
                }
            };

            Descifrar.Click += delegate
            {
                if (Clave.Text.Equals(""))
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    AlertDialog error = alert.Create();
                    error.SetTitle("Error");
                    error.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                    error.SetMessage("Debes colocar la clave para Descifrado");
                    error.SetButton("OK", (w, a) => { });
                    error.Show();
                }
                else
                {
                    int clave = Convert.ToInt32(Clave.Text);
                    if (clave > 76 || clave == 0)
                    {
                        AlertDialog.Builder alert = new AlertDialog.Builder(this);
                        AlertDialog error = alert.Create();
                        error.SetTitle("Error");
                        error.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                        error.SetMessage("La clave no es un numero valido, la clave debe ser un numero de 1 a 76");
                        error.SetButton("OK", (w, a) => { });
                        error.Show();
                    }
                    else if (Mensaje.Text == "")
                    {
                        AlertDialog.Builder alert = new AlertDialog.Builder(this);
                        AlertDialog error = alert.Create();
                        error.SetTitle("Error");
                        error.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                        error.SetMessage("No hay mensaje para descifrar");
                        error.SetButton("OK", (w, a) => { });
                        error.Show();
                    }
                    else
                    {
                        string MsjeDescifrado = descifrar(Mensaje.Text, clave);
                        Mensaje.Text = MsjeDescifrado;
                        Msj.Text = "Mensaje Descifrado:";
                    }
                }
            };

            Enviar.Click += (s, e) =>
            {
                if (Mensaje.Text == "")
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    AlertDialog error = alert.Create();
                    error.SetTitle("Error");
                    error.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                    error.SetMessage("No hay ningun mensaje para enviar");
                    error.SetButton("OK", (w, a) => { });
                    error.Show();
                }
                else
                {
                    Intent email = new Intent(Intent.ActionSend);
                    email.PutExtra(Intent.ExtraText, Mensaje.Text.ToString());
                    email.SetType("message/rfc822");
                    StartActivity(Intent.CreateChooser(email, "Enviar por medio de:"));
                }
            };



            Borrar.Click += delegate
            {
                Clave.Text = "0";
                Mensaje.Text = "";
                Msj.Text = "Mensaje:";
            };
        }
        static string cifrar(string mensaje, int clave)
        {
            String cifrado = "";
            if (clave > 0 && clave < abc.Length)
            {
                for (int i = 0; i < mensaje.Length; i++)
                {
                    int posCaracter = getPosABC(mensaje[i]);

                    if (posCaracter != -1)
                    {
                        int pos = posCaracter + clave;
                        while (pos >= abc.Length)
                        {
                            pos = pos - abc.Length;
                        }
                        cifrado += abc[pos];
                    }
                    else
                    {
                        cifrado += mensaje[i];
                    }
                }
            }
            return cifrado;
        }
        static string descifrar(string mensaje, int clave)
        {
            String cifrado = "";
            if (clave > 0 && clave < abc.Length)
            {
                for (int i = 0; i < mensaje.Length; i++)
                {
                    int posCaracter = getPosABC(mensaje[i]);
                   
                    if (posCaracter != -1)
                    {
                        int pos = posCaracter - clave;
                        while (pos < 0)
                        {
                            pos = pos + abc.Length;
                        }
                        cifrado += abc[pos];
                    }
                    else
                    {
                        cifrado += mensaje[i];
                    }
                }
            }
            return cifrado;
        }
        static int getPosABC(char caracter)
        {
            for (int i = 0; i < abc.Length; i++)
            {
                if (caracter == abc[i])
                {
                    return i;
                }
            }

            return -1;
        }


    }
}

Link para descargar el APK V2.0: You are not allowed to view links. Register or Login
« Última modificación: Agosto 30, 2016, 04:50:29 pm por Zentraedi »

Conectado zolo

  • Consigliere
  • Master
  • *****
  • Mensajes: 23056
  • Un Mes, Un Año o Toda Una Vida, Da Igual, Estare
Re:Cifrado de Cesar app - By Zentraedi
« Respuesta #1 en: Agosto 29, 2016, 10:10:32 pm »
En este campo, poco puedo decir, no es el mio, soy un zote.

Solo darte las gracias por tu aporte y animarte a seguir practicando y posteandolo aqui

Saludos
You are not allowed to view links. Register or Login

Desconectado Zentraedi

  • Moderator
  • Habitual
  • *****
  • Mensajes: 134
  • "El universo cantara mi canción" Nekki Basara
Re:Cifrado de Cesar app - By Zentraedi
« Respuesta #2 en: Agosto 29, 2016, 10:23:02 pm »
Gracias @zolo pronto actualizare la app haciendola un poco mas interesante. Es intereresante la criptografia y por eso lo aplique con lo primero que aprendi.

Tags:
Tags:

 


SMF 2.0.19 | SMF © 2016, Simple Machines
Paginas Afiliadas
Twitter - FaceBook - Daraxblog
Designed by Smf Personal