Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. public String encrypt(String klartext) {
  2.         String cipherText = "";
  3.         for (int i = 0; i < klartext.length(); i++) {
  4.             int charPosition = -1;
  5.             char replaceVal;
  6.             int keyVal = -1;
  7.             char val = klartext.charAt(i);
  8.  
  9.             if (Character.isUpperCase(val)) {
  10.                 charPosition = ALPHABET_UPPER.indexOf(val);
  11.                 if (charPosition != -1) {
  12.                     keyVal = (offset + charPosition) % 26;
  13.                     replaceVal = ALPHABET_UPPER.charAt(keyVal);
  14.                 } else {
  15.                     replaceVal = klartext.charAt(i);
  16.                 }
  17.             } else {
  18.                 charPosition = ALPHABET_LOWER.indexOf(val);
  19.                 if (charPosition != -1) {
  20.                     replaceVal = ALPHABET_LOWER.charAt(charPosition);
  21.                 } else {
  22.                     replaceVal = klartext.charAt(i);
  23.                 }
  24.             }
  25.             cipherText += replaceVal;
  26.         }
  27.         return cipherText;
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement