Advertisement
Guest User

almosttooeasy

a guest
Nov 27th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package de.unistuttgart.iaas.pse.ex05.p3;
  2.  
  3. import java.util.*;
  4.  
  5. public class Caesar {
  6.  
  7.     public static List<String> cipher(String text) {
  8.     List<String> ciphersList = new ArrayList<String>();
  9.     for (int shift = 0; shift <= 26; shift++) {
  10.         String cipher = "";
  11.         for (int i = 0; i < text.length(); i++) {
  12.         char currentLetter = text.charAt(i);
  13.         if (currentLetter >= 65 && currentLetter <= 90) {
  14.             int tmpLetter = currentLetter + shift;
  15.             if (tmpLetter > 90) {
  16.             cipher += (char) (currentLetter + (shift - 26));
  17.             // System.out.println(cipher);
  18.             } else {
  19.             cipher += (char) (currentLetter + shift);
  20.             // ciphersList.add(i, cipher);
  21.             // System.out.println(cipher);
  22.             }
  23.  
  24.         } else if (currentLetter >= 97 && currentLetter <= 122) {
  25.             int tmpLetter = currentLetter + shift;
  26.             if (tmpLetter > 122) {
  27.             cipher += (char) (currentLetter + (shift - 26));
  28.             // ciphersList.add(i, cipher);
  29.             // System.out.println(cipher);
  30.             } else {
  31.             cipher += (char) (currentLetter + shift);
  32.             // ciphersList.add(i, cipher);
  33.             // System.out.println(cipher);
  34.             }
  35.         } else if (currentLetter == 32) {
  36.             cipher += " ";
  37.         }
  38.         }
  39.  
  40.         ciphersList.add(shift, cipher);
  41.  
  42.     }
  43.  
  44.     return ciphersList;
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement