Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SzyfrCezara {
  4.  
  5.     public SzyfrCezara() {
  6.     }
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner in = new Scanner(System.in);
  10.         System.out.println("Wpisz tekst do zakodowania: ");
  11.         String text = in.nextLine();
  12.         in.close();
  13.         String zaszyfrowane = SzyfrCezara.szyfrowanie(text);
  14.         System.out.println(zaszyfrowane);
  15.     }
  16.  
  17.     public static String szyfrowanie(String wiadomosc) {
  18.         StringBuilder sb = new StringBuilder(wiadomosc);
  19.         int przesuniecie = 3;
  20.         for (int i = 0; i < sb.length(); i++) {
  21.             int c = (int) sb.charAt(i);
  22.             if ((c + przesuniecie > 90) && (c + przesuniecie <= 93)) {
  23.                 c = 64 + (przesuniecie - (90 - c));
  24.             } else if ((c + przesuniecie >= 65) && (c + przesuniecie <= 90)) {
  25.                 c += przesuniecie;
  26.             } else if (c == 32) {
  27.             } else {
  28.                 String porazka = "Wprowadzono nieprawidłowy tekst";
  29.                 return porazka;
  30.             }
  31.             sb.setCharAt(i, (char) c);
  32.         }
  33.         return sb.toString();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement