I need help completeing this assignment. What I need is the mathematical written
ID: 3864565 • Letter: I
Question
I need help completeing this assignment. What I need is the mathematical written algorithm part a. completed...
a. Develop a Caesar cipher-type encryption algorithm with a little more complexity in it. For example, the algorithm could alternatively shift the cleartext letters positive and negative by the amount of the key value. Variations on this are limitless.
b. Select a single-digit key.
14
c. Code a short message using the algorithm and key.
uccr acfbwbu dfctsggcf
d. Give your instructor the algorithm, key, cleartext, and ciphertext.
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
O
P
Q
R
S
T
U
V
W
X
Y
Z
A
B
C
D
E
F
G
H
I
J
K
L
M
N
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
My message is Good Morning Professor
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
O
P
Q
R
S
T
U
V
W
X
Y
Z
A
B
C
D
E
F
G
H
I
J
K
L
M
N
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Explanation / Answer
Algorithm:
input: algorithm,key,plaintext,ciphertext
boolean subtract = false;
String cipher="";
for i in plaintext{
if (algorithm>0) {
if(i%algorithm==0){
subtract = !subtract;
}
}
if (message.charAt(i) != ' ') {
char dec = message.charAt(i);
int v;
if (subtract) {
v = dec + (26-key);
} else {
v = dec + key;
}
v = v-97;
v = v%26;
v+= 97;
cipher += (char) v;
} else {
cipher+= " ";
}
}
Equivalent Java Code:
public class Caeser {
static int key = 14;
static int algorithm = 1;
public static void main(String[] args){
String message = "good morning professor";
String cipher = encrypt(message);
decrypt(cipher);
}
static String encrypt(String message){
boolean subtract = false;
String cipher="";
for(int i = 0;i<message.length();i++){
if (algorithm>0) {
if(i%algorithm==0){
subtract = !subtract;
}
}
if (message.charAt(i) != ' ') {
char dec = message.charAt(i);
int v;
if (subtract) {
v = dec + (26-key);
} else {
v = dec + key;
}
v = v-97;
v = v%26;
v+= 97;
cipher += (char) v;
} else {
System.out.print(" ");
cipher+= " ";
}
}
System.out.println(cipher);
return cipher;
}
static void decrypt(String message){
boolean subtract = false;
String cipher="";
for(int i = 0;i<message.length();i++){
if (algorithm>0) {
if(i%algorithm==0){
subtract = !subtract;
}
}
if (message.charAt(i) != ' ') {
char dec = message.charAt(i);
int v;
if (subtract) {
v = dec + key;
} else {
v = dec + (26-key);
}
v = v-97;
v = v%26;
v+= 97;
cipher += (char) v;
} else {
System.out.print(" ");
cipher+= " ";
}
}
System.out.println(cipher);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.