simplesroger

CifradorSustitucionMonoalfabeticoDesplazamientoN.java

Jun 2nd, 2012
4,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. /*
  2.  * Dudas y/o comentarios... :D
  3.  */
  4. package unsch.efpis.cifrador;
  5.  
  6. /**
  7.  *
  8.  * @author [email protected]
  9.  */
  10. public class CifradorSustitucionMonoalfabeticoDesplazamientoN {
  11.  
  12.     private static int desplazamientoN = 0;
  13.     char tablaCesar[] = {
  14.         'A', 'B', 'C', 'D', 'E',
  15.         'F', 'G', 'H', 'I', 'J',
  16.         'K', 'L', 'M', 'N', 'Ñ',
  17.         'O', 'P', 'Q', 'R', 'S',
  18.         'T', 'U', 'V', 'W', 'X',
  19.         'Y', 'Z'
  20.     };
  21.  
  22.     private int getDesplazamientoN() {
  23.         return desplazamientoN;
  24.     }
  25.  
  26.     public void setDesplazamientoN(int desplazamientoN) {
  27.         this.desplazamientoN = desplazamientoN;
  28.     }
  29.  
  30.     public char getTextoCifrado(char parTextoClaro) {
  31.         int indiceX = 0;
  32.  
  33.         for (int i = 0; i < tablaCesar.length; i++) {
  34.             if (parTextoClaro == tablaCesar[i]) {
  35.                 indiceX = i;
  36.                 break;
  37.             }
  38.         }
  39.  
  40.         return tablaCesar[(indiceX + getDesplazamientoN()%27) % 27];
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment