Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class part3 {
  2.     public static void main(String[] args) {
  3.         String decryptKey = "QWERTYUIOPASDFGHJKLZXCVBNM";
  4.         String decryptKey2 = "qwertyuiopasdfghjklzxcvbnm";
  5.         String msg = "Hn fig vky dckm ephl, fig pkwc oie cwcdfephyo bidrhyo.\n" +
  6.                      "Bcss miyc hymccm!\n" +
  7.                      "Figd jdiodkz pkm lgvvcllngssf mcvdfjecm epc zcllkoc.\n";
  8.         int i;
  9.         int index = 0;
  10.         int index2 = 0;
  11.        
  12.         for (i = 0; i < msg.length(); i++) {
  13.             char c = msg.charAt(i);
  14.                 if (Character.isUpperCase(c)) {
  15.                     char charDecrypt = Character.toUpperCase(c);
  16.                     index = charDecrypt - 'A';
  17.                     System.out.print(decryptKey.charAt(index));    
  18.                 }
  19.                 else if (Character.isLowerCase(c) ) {
  20.                     char charDecrypt2 = Character.toLowerCase(c);
  21.                     index2 = charDecrypt2 - 'a';
  22.                     System.out.print(decryptKey2.charAt(index2));
  23.                 }
  24.                 else {
  25.                     System.out.print(c);
  26.                 }
  27.         }
  28.     }
  29. }
  30.  
  31. // Output: If you can read this, you have got everything working.
  32. Well done indeed!
  33. Your program had successfully decrypted the message.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement