Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class CipherText {
  4. private static String cipherCode = "CĆDEĘFGHIJKLŁMNŃOÓPRSŚTUWYZŹŻAĄB";
  5. private static String alfabet = "AĄBCĆDEĘFGHIJKLŁMNŃOÓPRSŚTUWYZŹŻ";
  6. private static char[] CipherArray = new char[cipherCode.length()];
  7. private static char[] AlfabetArray = new char[alfabet.length()];
  8. public static String cipher(String msg, int shift){
  9. for(int i = 0; i < cipherCode.length();i++){
  10. CipherArray[i] = (char) (cipherCode.charAt(i));
  11. AlfabetArray[i] = (char) (alfabet.charAt(i));
  12. }
  13. String s = "";
  14. int len = msg.length();
  15. for(int x = 0; x < len; x++){
  16. char z = (char)(msg.charAt(x));
  17. if(z == ' '){
  18. s += " ";
  19. }
  20. else if(z != ' '){
  21. for(int i = 0 ; i < AlfabetArray.length;i++){
  22. if(z == AlfabetArray[i]){
  23. s+= CipherArray[i];
  24. }
  25.  
  26. }
  27.  
  28. }
  29.  
  30. }
  31. return s;
  32.  
  33. }
  34. }
  35.  
  36. public class GlownaKlasa {
  37. public static void main(String[] args){
  38. String text = "Ala ma kota";
  39. String code = CipherText.cipher("Ato niespodzianka", 3);
  40. System.out.println(code);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement