Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.50 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package mcobbcnc142cryptography5_1lab;
  7.  
  8. /**
  9.  *
  10.  * @author Matt Cobb
  11.  */
  12.  
  13. import java.util.Arrays;
  14. import java.util.Scanner;
  15.  
  16. public class MCobbCNC142Cryptography5_1Lab {
  17.  
  18.     /**
  19.      * @param args the command line arguments
  20.      */
  21.     public static void main(String[] args) {
  22.         //creates scanner object
  23.         Scanner input = new Scanner(System.in);
  24.        
  25.         //prompts user for input
  26.         System.out.println("Enter text to be encrypted. Make sure the text is "
  27.                 + "all lower-case and on a single line");
  28.         String message = input.nextLine();
  29.        
  30.         //separates message into an array of characters
  31.         char messageCharArray[] = message.toCharArray();
  32.        
  33.         //char array of the alphabet
  34.         String alphabet = "abcdefghijklmnopqrstuvwxyz";
  35.         char alphabetCharArray[] = alphabet.toCharArray();
  36.        
  37.         //char array of the cipher key
  38.         String cipherKey = "d9xsfz721ehcv3itpga5q0lkjr";
  39.         char cipherKeyArray[] = cipherKey.toCharArray();
  40.        
  41.         //converts each letter of the message to the
  42.         //corresponding letter in the key
  43.         for(int i = 0; i < message.length(); i++) {
  44.        
  45.             if (messageCharArray[i] == alphabetCharArray[0]) {
  46.            
  47.                 messageCharArray[i] = cipherKeyArray[0];
  48.            
  49.             } else if (messageCharArray[i] == alphabetCharArray[1]) {
  50.            
  51.                 messageCharArray[i] = cipherKeyArray[1];
  52.            
  53.             } else if (messageCharArray[i] == alphabetCharArray[2]) {
  54.            
  55.                 messageCharArray[i] = cipherKeyArray[2];
  56.            
  57.             } else if (messageCharArray[i] == alphabetCharArray[3]) {
  58.            
  59.                 messageCharArray[i] = cipherKeyArray[3];
  60.            
  61.             } else if (messageCharArray[i] == alphabetCharArray[4]) {
  62.            
  63.                 messageCharArray[i] = cipherKeyArray[4];
  64.                
  65.             } else if (messageCharArray[i] == alphabetCharArray[5]) {
  66.            
  67.                 messageCharArray[i] = cipherKeyArray[5];
  68.            
  69.             } else if (messageCharArray[i] == alphabetCharArray[6]) {
  70.            
  71.                 messageCharArray[i] = cipherKeyArray[6];
  72.            
  73.             } else if (messageCharArray[i] == alphabetCharArray[7]) {
  74.            
  75.                 messageCharArray[i] = cipherKeyArray[7];
  76.            
  77.             } else if (messageCharArray[i] == alphabetCharArray[8]) {
  78.            
  79.                 messageCharArray[i] = cipherKeyArray[8];
  80.            
  81.             } else if (messageCharArray[i] == alphabetCharArray[9]) {
  82.            
  83.                 messageCharArray[i] = cipherKeyArray[9];
  84.            
  85.             } else if (messageCharArray[i] == alphabetCharArray[10]) {
  86.            
  87.                 messageCharArray[i] = cipherKeyArray[10];
  88.            
  89.             } else if (messageCharArray[i] == alphabetCharArray[11]) {
  90.            
  91.                 messageCharArray[i] = cipherKeyArray[11];
  92.            
  93.             } else if (messageCharArray[i] == alphabetCharArray[12]) {
  94.            
  95.                 messageCharArray[i] = cipherKeyArray[12];
  96.            
  97.             } else if (messageCharArray[i] == alphabetCharArray[13]) {
  98.            
  99.                 messageCharArray[i] = cipherKeyArray[13];
  100.            
  101.             } else if (messageCharArray[i] == alphabetCharArray[14]) {
  102.            
  103.                 messageCharArray[i] = cipherKeyArray[14];
  104.            
  105.             } else if (messageCharArray[i] == alphabetCharArray[15]) {
  106.            
  107.                 messageCharArray[i] = cipherKeyArray[15];
  108.            
  109.             } else if (messageCharArray[i] == alphabetCharArray[16]) {
  110.            
  111.                 messageCharArray[i] = cipherKeyArray[16];
  112.            
  113.             } else if (messageCharArray[i] == alphabetCharArray[17]) {
  114.            
  115.                 messageCharArray[i] = cipherKeyArray[17];
  116.            
  117.             } else if (messageCharArray[i] == alphabetCharArray[18]) {
  118.            
  119.                 messageCharArray[i] = cipherKeyArray[18];
  120.            
  121.             } else if (messageCharArray[i] == alphabetCharArray[19]) {
  122.            
  123.                 messageCharArray[i] = cipherKeyArray[19];
  124.            
  125.             } else if (messageCharArray[i] == alphabetCharArray[20]) {
  126.            
  127.                 messageCharArray[i] = cipherKeyArray[20];
  128.            
  129.             } else if (messageCharArray[i] == alphabetCharArray[21]) {
  130.            
  131.                 messageCharArray[i] = cipherKeyArray[21];
  132.            
  133.             } else if (messageCharArray[i] == alphabetCharArray[22]) {
  134.            
  135.                 messageCharArray[i] = cipherKeyArray[22];
  136.            
  137.             } else if (messageCharArray[i] == alphabetCharArray[23]) {
  138.            
  139.                 messageCharArray[i] = cipherKeyArray[23];
  140.            
  141.             } else if (messageCharArray[i] == alphabetCharArray[24]) {
  142.            
  143.                 messageCharArray[i] = cipherKeyArray[24];
  144.            
  145.             } else if (messageCharArray[i] == alphabetCharArray[25]) {
  146.            
  147.                 messageCharArray[i] = cipherKeyArray[25];
  148.            
  149.             }
  150.        
  151.         }
  152.        
  153.         System.out.println(messageCharArray);
  154.     }
  155.    
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement