Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Cipher. Make the constructor accept some text and a key. Encrypt the given text using the key. Use the following cipher:

Create a class called Cipher. Make the constructor accept some text and a key. Encrypt the given text using the key.
Use the following cipher:
Take the key and mod it by 26. Example: a key of 30 becomes 4.
If the character is a letter, shift it by the key, but 'wrap around' the alphabet if necessary.
If the character is not a letter, then shift it by the key but do not wrap.
Check the test cases for example.
Make getters to support the CipherDemo. Also, make two custom Exceptions called UselessKeyException and EmptyPlainText. In your constructor, throw UselessKeyException if the key is divisible by 26 and throw EmplyPainText if the plain text is zero characters.
Test Case 1
Enter some text to encrypt
abcENTER
Enter a key
1ENTER
Plain text: abc
Cipher text: bcd
Key: 1
Test Case 2
Enter some text to encrypt
ENTER
Enter a key
19ENTER
Error: Nothing to encrypt!
Test Case 3
Enter some text to encrypt
ENTER
Enter a key
23ENTER
Error: Nothing to encrypt!
Test Case 4
Enter some text to encrypt
BitCoin is cool but it has its problems.ENTER
Enter a key
1352ENTER
Error: Key is divisible by 26. That's a bad key!
Useless key: 1352
Test Case 5
Enter some text to encrypt
BitCoin is cool but it has its problems.ENTER
Enter a key
378ENTER
Plain text: BitCoin is cool but it has its problems.
Cipher text: PwhQcwb.wg.qccz.pih.wh.vog.whg.dfcpzsag<
Key: 378
Test Case 6
Enter some text to encrypt
BitCoin is cool but it has its problems.ENTER
Enter a key
376ENTER
Plain text: BitCoin is cool but it has its problems.
Cipher text: NufOauz,ue,oaax,ngf,uf,tme,ufe,bdanxqye:
Key: 376
Test Case 7
Enter some text to encrypt
BitCoin is cool but it has its problems.ENTER
Enter a key
374ENTER
Plain text: BitCoin is cool but it has its problems.
Cipher text: LsdMysx*sc*myyv*led*sd*rkc*sdc*zbylvowc8
Key: 374
Test Case 8
Enter some text to encrypt
BitCoin is cool but it has its problems.ENTER
Enter a key
372ENTER
Plain text: BitCoin is cool but it has its problems.
Cipher text: JqbKwqv(qa(kwwt(jcb(qb(pia(qba(xzwjtmua6
Key: 372
Test Case 9
Enter some text to encrypt
BitCoin is cool but it has its problems.ENTER
Enter a key
370ENTER
Plain text: BitCoin is cool but it has its problems.
Cipher text: HozIuot&oy&iuur&haz&oz&ngy&ozy&vxuhrksy4
Key: 370
Test Case 10
Enter some text to encrypt
With computer science, you can work in any industry.ENTER
Enter a key
52ENTER
Error: Key is divisible by 26. That's a bad key!
Useless key: 52
Test Case 11
Enter some text to encrypt
With computer science, you can work in any industry.ENTER
Enter a key
4220ENTER
Plain text: With computer science, you can work in any industry.
Cipher text: Eqbp(kwuxcbmz(akqmvkm4(gwc(kiv(ewzs(qv(ivg(qvlcabzg6
Key: 4220
Test Case 12
Enter some text to encrypt
With computer science, you can work in any industry.ENTER
Enter a key
0ENTER
Error: Key is divisible by 26. That's a bad key!
Useless key: 0
Test Case 13
Enter some text to encrypt
With computer science, you can work in any industry.ENTER
Enter a key
26ENTER
Error: Key is divisible by 26. That's a bad key!
Useless key: 26
Test Case 14
Enter some text to encrypt
With computer science, you can work in any industry.ENTER
Enter a key
4221ENTER
Plain text: With computer science, you can work in any industry.
Cipher text: Frcq)lxvydcna)blrnwln5)hxd)ljw)fxat)rw)jwh)rwmdbcah7
Key: 4221
Test Case 15
Enter some text to encrypt
With computer science, you can work in any industry.ENTER
Enter a key
5021ENTER
Plain text: With computer science, you can work in any industry.
Cipher text: Zlwk#frpsxwhu#vflhqfh/#brx#fdq#zrun#lq#dqb#lqgxvwub1
Key: 5021
Test Case 16
Enter some text to encrypt
Hello, my secret password is SIMCITY! Don't tell anyone! I've used this for 400 days.ENTER
Enter a key
23ENTER
Plain text: Hello, my secret password is SIMCITY! Don't tell anyone! I've used this for 400 days.
Cipher text: EbiilC7jv7pbzobq7mxpptloa7fp7PFJZFQV87Alk>q7qbii7xkvlkb87F>sb7rpba7qefp7clo7KGG7axvpE
Key: 23
Test Case 17
Enter some text to encrypt
XYZENTER
Enter a key
1ENTER
Plain text: XYZ
Cipher text: YZA
Key: 1
Test Case 18
Enter some text to encrypt
ABCENTER
Enter a key
1ENTER
Plain text: ABC
Cipher text: BCD
Key: 1
Test Case 19
Enter some text to encrypt
xyzENTER
Enter a key
1ENTER
Plain text: xyz
Cipher text: yza
Key: 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions