Advertisement
HarrJ

Day 11 Cipher

Feb 12th, 2024 (edited)
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. public class Day11A {
  2.     public static void main(String[] args) {
  3.         CaesarCipher callCipher = new CaesarCipher();
  4.         String refTxt = "Joysis B8";
  5.         String resultTxt;
  6.         callCipher.setTxtIn(refTxt);
  7.         callCipher.setIsEncrypt(true);
  8.         resultTxt = callCipher.getTxtOut();
  9.         System.out.println("reference: " + refTxt);
  10.         System.out.println("result: " + resultTxt);
  11.     }
  12. }
  13.  
  14. class CaesarCipher {
  15.     private String txtIn;
  16.     private String txtOut;
  17.     private boolean isEncrypt;
  18.  
  19.     /**
  20.      * @param txtIn the txtIn to set
  21.      */
  22.     public void setTxtIn(String txtIn) {
  23.         this.txtIn = txtIn;
  24.     }
  25.  
  26.     /**
  27.      * @return the txtOut
  28.      */
  29.     public String getTxtOut() {
  30.         if (isEncrypt) {
  31.             encode();
  32.         }
  33.         return txtOut;
  34.     }
  35.  
  36.     /**
  37.      * @param isEncrypt the isEncrypt to set
  38.      */
  39.     public void setIsEncrypt(boolean isEncrypt) {
  40.         this.isEncrypt = isEncrypt;
  41.     }
  42.    
  43.     private void encode() {
  44.         int direction = -3;
  45.         char[] txtArray = txtIn.toCharArray();
  46.         for (int i = 0; i < txtArray.length; i++) {
  47.             if ( (____ && _____) || (_____ && ______)) { // D~Z d~z
  48.                 txtArray[i] += direction;
  49.             } else if ((____ && _____) || (_____ && ______)) { // ABC abc
  50.                 txtArray[i] += 23;
  51.             }
  52.         }
  53.         txtOut = new String(txtArray);
  54.     }
  55. }
  56.  
  57. //--------------------------------------------
  58. public class Day11C {
  59.     public static void main(String[] args) {
  60.         int num1 = 12, num2 = 0, numRes;
  61.         //String test = "123.66";
  62.         //System.out.println(test + " : " + NumberUtils.isCreatable(test));
  63.         //test = "-123.66";
  64.         //System.out.println(test + " : " + NumberUtils.isCreatable(test));
  65.         //test = "123.66a";
  66.         //System.out.println(test + " : " + NumberUtils.isCreatable(test));
  67.        
  68.         try {
  69.             numRes = num1 + num2;
  70.             System.out.println("result +: " + numRes);
  71.             numRes = num1 / num2;
  72.             System.out.println("result /: " + numRes);
  73.             numRes = num1 - num2;
  74.             System.out.println("result -: " + numRes);
  75.         } catch (Exception e) {
  76.             System.out.println("ay may mali");
  77.             System.out.println(e);
  78.         }
  79.     }
  80. }
  81.  
  82. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. package week2;
  84.  
  85. public class Day11D {
  86.     public static void main(String[] args) {
  87.         String[] numList = {"12", "42" ,"3E", "55", "twelve", "88"};
  88.         int currNum, total = 0;
  89.         for (int i = 0; i <= numList.length; i++) {
  90.             try {
  91.                 currNum = Integer.parseInt(numList[i]);
  92.                 total += currNum;
  93.                 System.out.print(currNum + (i < numList.length ? " + " : " = "));
  94.             } catch (Exception e) {
  95.                 System.out.println(">> " + e.toString());
  96.             }
  97.         }
  98.        
  99.         System.out.println("Total: " + total);
  100.     }
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement