Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4.  
  5. public class Cesar_verschlüsselung {
  6.  
  7. public static void main(String[] args){
  8.  
  9. System.out.print("Um wie viele Buchstaben soll vershoben werden ?: ");
  10. int verschiebung = In.readInt();
  11. System.out.println("Bitte Nachricht eingeben: ");
  12. String s = In.readString();
  13.  
  14. System.out.println(verschlüsselung_string(s, verschiebung));
  15.  
  16. }
  17.  
  18.  
  19. public static String verschlüsselung_string (String s, int verschiebung){
  20.  
  21. String ret = "";
  22. for (int i = 0;
  23. i < s.length();
  24. i++){
  25.  
  26. ret += verschlüsseln(s.charAt(i), verschiebung);
  27. }
  28.  
  29. return ret;
  30. }
  31.  
  32. public static char verschlüsseln(char c, int verschiebung){
  33.  
  34. if ((int)c + verschiebung > 122);{
  35. return (char) ((int) c + verschiebung - 26);
  36.  
  37. }
  38. else
  39. {
  40. return (char) ((int) c + verschiebung);
  41. }
  42.  
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement