Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Crytti 2.0 - Crytti Relase 1.0.java

Crytti Relase 1.0.java

Caricato da: Mutelg
Scarica il programma completo

  1. /**
  2.  * Autore :Alenadri Enrico
  3.  * Classe : III G
  4.  * Data :  28/01/2009
  5.  * Nome File:Crytti.java
  6.  */
  7.  
  8.  import javax.swing.JOptionPane;
  9.  
  10. public class Crytti {
  11.  
  12.     /**
  13.      * @param args the command line arguments
  14.      */
  15.     public static void main(String[] args)
  16.        {
  17.                 boolean ripDom = true,
  18.                         ripLet=true;
  19.         char letteraM,
  20.              letteraK;
  21.         int lunFrase=0,
  22.             numeroM=0,
  23.             numeroK=0,
  24.             i,
  25.             k,
  26.             lunChiave=0,
  27.             conKey=1;
  28.         String domanda="",
  29.                frase="",
  30.                mex="",
  31.                key="";
  32.         char[] testo = new char[200];
  33.         char[][] tabCri = {
  34.                                         {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'},
  35.                                         {'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a'},
  36.                                         {'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b'},
  37.                                         {'d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c'},
  38.                                         {'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d'},
  39.                                         {'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e'},
  40.                                         {'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f'},
  41.                                         {'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g'},
  42.                                         {'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h'},
  43.                                         {'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i'},
  44.                                         {'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j'},
  45.                                         {'l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k'},
  46.                                         {'m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l'},
  47.                                         {'n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m'},
  48.                                         {'o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n'},
  49.                                         {'p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'},
  50.                                         {'q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'},
  51.                                         {'r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q'},
  52.                                         {'s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r'},
  53.                                         {'t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s'},
  54.                                         {'u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t'},
  55.                                         {'v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u'},
  56.                                         {'w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v'},
  57.                                         {'x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w'},
  58.                                         {'y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x'},
  59.                                         {'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'},
  60.  
  61.                                                   };
  62.  
  63.         do{
  64.                    try{
  65.                        domanda = JOptionPane.showInputDialog("Cosa Vuoi fare?  'crittare o decrittare' ");
  66.                        domanda = domanda.toLowerCase();
  67.                        if(domanda.equals("crittare"))ripDom=false;
  68.                        if(domanda.equals("decrittare"))ripDom=false;
  69.                    }catch(NullPointerException ex)
  70.                    {
  71.                         ripDom=true;
  72.                    }
  73.  
  74.                 }while(ripDom==true);
  75.  
  76.  
  77.  
  78.  
  79.                 if(domanda.equals("crittare"))
  80.                   {
  81.  
  82.                    do{
  83.                           ripLet=false;
  84.               try{
  85.                           frase = JOptionPane.showInputDialog("Iinserisci la frase da Crittare: ");
  86.                           frase = frase.toLowerCase();
  87.                           lunFrase = frase.length();
  88.                       }catch(NullPointerException ex)
  89.                           {
  90.                                 ripLet=true;
  91.                       }
  92.  
  93.                   }while(ripLet==true);
  94.  
  95.                   do{
  96.                          ripDom=false;
  97.                     try{
  98.                     key = JOptionPane.showInputDialog("Inserisci la chiave di Crittaggio: ");
  99.                         key = key.toLowerCase();
  100.                         lunChiave = key.length();
  101.                         if(key.equals(""))ripDom=true;
  102.                         }catch(NullPointerException ex)
  103.                         {
  104.                           ripDom=true;
  105.                      }
  106.  
  107.                 }while(ripDom==true);
  108.                 for(i=1;i<=lunFrase;i++)
  109.                    {
  110.                           letteraM = frase.charAt(i-1);
  111.                           if(letteraM == ' ')
  112.                              testo[i]=' ';
  113.                           else
  114.                             {
  115.                              letteraK = key.charAt(conKey-1);
  116.                              numeroM = letteraM-97;
  117.                              numeroK = letteraK-97;
  118.                              testo[i] = tabCri[numeroM][numeroK];
  119.                              if(conKey==lunChiave)conKey=0;
  120.                              conKey++;
  121.                              }
  122.                     }
  123.  
  124.  
  125.           for(i=1;i<=lunFrase;i++)
  126.              {
  127.                            if(testo[i]==' ')
  128.                               mex=mex+" ";
  129.                            else
  130.                            {
  131.                              mex+=testo[i];
  132.                             }
  133.                       }
  134.  
  135.         System.out.println("Messaggio Crittato:\n"+mex);
  136.                 JOptionPane.showMessageDialog(null,"Testo crittato : \n"+mex+ "\n\nChiave di Decrittaggio :\n"+key);
  137.  
  138.                 }
  139.                 else
  140.                 {
  141.                    do{
  142.                           ripLet=false;
  143.               try{
  144.                           mex = JOptionPane.showInputDialog("Inserisci la stringa da decrittare:");
  145.                           mex = mex.toLowerCase();
  146.                           lunFrase = mex.length();
  147.                       }catch(NullPointerException ex)
  148.                           {
  149.                                 ripLet=true;
  150.                       }
  151.  
  152.                   }while(ripLet==true);
  153.  
  154.  
  155.                   do{
  156.                          ripDom=false;
  157.                     try{
  158.                     key = JOptionPane.showInputDialog("Inserisci la chiave di Crittaggio: ");
  159.                         key = key.toLowerCase();
  160.                         lunChiave = key.length();
  161.                         if(key.equals(""))ripDom=true;
  162.                         }catch(NullPointerException ex)
  163.                         {
  164.                           ripDom=true;
  165.                      }
  166.  
  167.                 }while(ripDom==true);
  168.  
  169.                 for(k=1;k<=lunFrase;k++)
  170.                    {
  171.                         letteraM = mex.charAt(k-1);
  172.                         if(letteraM == ' ')
  173.                              testo[k] = ' ';
  174.                         else
  175.                           {
  176.                             letteraK = key.charAt(conKey-1);
  177.                             numeroK = letteraK-97;
  178.                             for(i=0;i<=25;i++)
  179.                                {
  180.                                         if(tabCri[numeroK][i]==letteraM)
  181.                                           {
  182.                                            numeroM = i+1;
  183.                                            i=26;
  184.                                           }
  185.                                    }
  186.                                 testo[k]= (char) (numeroM+96);
  187.                             if(conKey==lunChiave)conKey=0;
  188.                              conKey++;
  189.                           }
  190.  
  191.                    }
  192.  
  193.             for(i=1;i<=lunFrase;i++)
  194.              {
  195.                            if(testo[i]==' ')
  196.                               frase+=" ";
  197.                            else
  198.                            {
  199.                              frase+=testo[i];
  200.                             }
  201.                       }
  202.  
  203.  
  204.                   JOptionPane.showMessageDialog(null,"Ecco il testo in chiaro : \n"+frase);
  205.  
  206.                 }
  207.  
  208.  
  209.  
  210.     }
  211. }