Skip to content

S102_OneTimePad_Easy

William O Simpson edited this page Mar 6, 2020 · 9 revisions

Portfolio Home Page

Problem Statement

For all three problems, store the alphabet in a static array that contains only capital letters i.e. the length of the array should be 26, and you may have to convert any input text to uppercase.

Your Alphabet should be stored as follows, but with all the alphabet:

final char alphabet[] = {A,B,C};

You should have a method to convert a letter to an index of the alphabet array, and vice versa.

Easy:

A simple way to encrypt text is to simply shift each letter forward by a given number, n. When n = 13, and using just letters, the message is:

Message:

M E E T   M E   A T   T H R E E .

Cipher text:

Z R R G  Z R  N G  G U E R R .

You are to create a program to enter a message and the value of n, and then display the cipher text. You must also have a program that decrypts the cipher text given an n value.

User Documentation

To start encrypting simply run the program. The program will ask for a message to encrypt and afterwards a number of shifts that should be informed. After both values are entered an encrypted message will be created and printed to the console. To encrypt another message choose the yes option. When you no longer wish to encrypt messages simply respond no when asked if you're like to encrypt another message. All input will be switched to upper case and encrypted that way. This program only encrypts with upper case letters and numbers.

Developer Documentation

The program consists of 2 main classes OneTimePad and Encrypter. The Encrypter class handles all of the encrypting and shifting of the letters. All chars that can be encrypted are within the alphabet in this class and if a character is not within the alphabet it will not be shifted. The OneTimePad class handles user input and starting the encryption. It's starts from the run() method and starts asking for inputs. If and input is invalid it rejects it and asks for the same input again. OneTimePadDriver simply creates an instance of OneTimePad and runs the program.

UML Diagram: UML Diagram

JavaDocs

The java documents are served from a local web server on this machine. To start the web server, navigate to the directory immediately above where the source code is checked out (i.e. ~/git ) and then use "python -m SimpleHTTPServer" in that directory.

cd ~/git
python -m SimpleHTTPServer&

Note: if you are running python 3 (which you can check via opening a terminal and typing: python --version), then the command is:

python3 -m http.server

Click Here to View JavaDocs

Source Code

Link to the source code