Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package unsch.efpis.cifrador;
  2.  
  3. /**
  4.  *
  5.  * @author sin_querer@hotmail.com
  6.  */
  7. public class DescifradorVigenere {
  8.  
  9.     char tablaCesar[] = {
  10.         'A', 'B', 'C', 'D', 'E',
  11.         'F', 'G', 'H', 'I', 'J',
  12.         'K', 'L', 'M', 'N', 'Ñ',
  13.         'O', 'P', 'Q', 'R', 'S',
  14.         'T', 'U', 'V', 'W', 'X',
  15.         'Y', 'Z'
  16.     };
  17.  
  18.     public char getTextoDescifrado(char parTextoCifrado, char parTextoClave) {
  19.         int indiceCharTextoCifrado = 0;
  20.         int indiceCharTextoClave = 0;
  21.  
  22.         for (int i = 0; i < tablaCesar.length; i++) {
  23.             if (parTextoCifrado == tablaCesar[i]) {
  24.                 indiceCharTextoCifrado = i;
  25.                 break;
  26.             }
  27.         }
  28.  
  29.         for (int j = 0; j < tablaCesar.length; j++) {
  30.             if (parTextoClave == tablaCesar[j]) {
  31.                 indiceCharTextoClave = j;
  32.                 break;
  33.             }
  34.         }
  35.         if(indiceCharTextoCifrado >= indiceCharTextoClave)
  36.             return tablaCesar[(indiceCharTextoCifrado - indiceCharTextoClave) % 27];
  37.         else
  38.             return tablaCesar[27-(indiceCharTextoClave - indiceCharTextoCifrado)];
  39.     }    
  40. }