Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mcobbcnc142cryptography5_1lab;
- /**
- *
- * @author Matt Cobb
- */
- import java.util.Arrays;
- import java.util.Scanner;
- public class MCobbCNC142Cryptography5_1Lab {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- //creates scanner object
- Scanner input = new Scanner(System.in);
- //prompts user for input
- System.out.println("Enter text to be encrypted. Make sure the text is "
- + "all lower-case and on a single line");
- String message = input.nextLine();
- //separates message into an array of characters
- char messageCharArray[] = message.toCharArray();
- //char array of the alphabet
- String alphabet = "abcdefghijklmnopqrstuvwxyz";
- char alphabetCharArray[] = alphabet.toCharArray();
- //char array of the cipher key
- String cipherKey = "d9xsfz721ehcv3itpga5q0lkjr";
- char cipherKeyArray[] = cipherKey.toCharArray();
- //converts each letter of the message to the
- //corresponding letter in the key
- for(int i = 0; i < message.length(); i++) {
- if (messageCharArray[i] == alphabetCharArray[0]) {
- messageCharArray[i] = cipherKeyArray[0];
- } else if (messageCharArray[i] == alphabetCharArray[1]) {
- messageCharArray[i] = cipherKeyArray[1];
- } else if (messageCharArray[i] == alphabetCharArray[2]) {
- messageCharArray[i] = cipherKeyArray[2];
- } else if (messageCharArray[i] == alphabetCharArray[3]) {
- messageCharArray[i] = cipherKeyArray[3];
- } else if (messageCharArray[i] == alphabetCharArray[4]) {
- messageCharArray[i] = cipherKeyArray[4];
- } else if (messageCharArray[i] == alphabetCharArray[5]) {
- messageCharArray[i] = cipherKeyArray[5];
- } else if (messageCharArray[i] == alphabetCharArray[6]) {
- messageCharArray[i] = cipherKeyArray[6];
- } else if (messageCharArray[i] == alphabetCharArray[7]) {
- messageCharArray[i] = cipherKeyArray[7];
- } else if (messageCharArray[i] == alphabetCharArray[8]) {
- messageCharArray[i] = cipherKeyArray[8];
- } else if (messageCharArray[i] == alphabetCharArray[9]) {
- messageCharArray[i] = cipherKeyArray[9];
- } else if (messageCharArray[i] == alphabetCharArray[10]) {
- messageCharArray[i] = cipherKeyArray[10];
- } else if (messageCharArray[i] == alphabetCharArray[11]) {
- messageCharArray[i] = cipherKeyArray[11];
- } else if (messageCharArray[i] == alphabetCharArray[12]) {
- messageCharArray[i] = cipherKeyArray[12];
- } else if (messageCharArray[i] == alphabetCharArray[13]) {
- messageCharArray[i] = cipherKeyArray[13];
- } else if (messageCharArray[i] == alphabetCharArray[14]) {
- messageCharArray[i] = cipherKeyArray[14];
- } else if (messageCharArray[i] == alphabetCharArray[15]) {
- messageCharArray[i] = cipherKeyArray[15];
- } else if (messageCharArray[i] == alphabetCharArray[16]) {
- messageCharArray[i] = cipherKeyArray[16];
- } else if (messageCharArray[i] == alphabetCharArray[17]) {
- messageCharArray[i] = cipherKeyArray[17];
- } else if (messageCharArray[i] == alphabetCharArray[18]) {
- messageCharArray[i] = cipherKeyArray[18];
- } else if (messageCharArray[i] == alphabetCharArray[19]) {
- messageCharArray[i] = cipherKeyArray[19];
- } else if (messageCharArray[i] == alphabetCharArray[20]) {
- messageCharArray[i] = cipherKeyArray[20];
- } else if (messageCharArray[i] == alphabetCharArray[21]) {
- messageCharArray[i] = cipherKeyArray[21];
- } else if (messageCharArray[i] == alphabetCharArray[22]) {
- messageCharArray[i] = cipherKeyArray[22];
- } else if (messageCharArray[i] == alphabetCharArray[23]) {
- messageCharArray[i] = cipherKeyArray[23];
- } else if (messageCharArray[i] == alphabetCharArray[24]) {
- messageCharArray[i] = cipherKeyArray[24];
- } else if (messageCharArray[i] == alphabetCharArray[25]) {
- messageCharArray[i] = cipherKeyArray[25];
- }
- }
- System.out.println(messageCharArray);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement