Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment03-18
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
harrison.pickett
Assessment03-18
Commits
45382c29
Commit
45382c29
authored
Jan 07, 2019
by
Thundy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
It's finished
parent
e56f0d16
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
154 additions
and
3 deletions
+154
-3
AssessmentPartThree.java
src/AssessmentPartThree.java
+154
-3
No files found.
src/AssessmentPartThree.java
View file @
45382c29
public
class
AssessmentPartThree
{
public
class
AssessmentPartThree
{
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
...
@@ -8,6 +7,7 @@ public class AssessmentPartThree {
...
@@ -8,6 +7,7 @@ public class AssessmentPartThree {
// - so a becomes b, b becomes c, etc
// - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on
// If a value of -2 is chosen a becomes y, b becomes z and so on
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
{
{
// 05 - encryptedCharacter
// 05 - encryptedCharacter
...
@@ -17,7 +17,143 @@ public class AssessmentPartThree {
...
@@ -17,7 +17,143 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
// Any other characters are returned unchanged
return
'a'
;
char
encryptedCharacter
=
'a'
;
int
charNo
=
0
;
//initializing the variables used
switch
(
theChar
)
//switch tree converts the character to an integer number. 1-26 for lowercase and 27-52 for uppercase
{
case
'a'
:
charNo
=
1
;
break
;
case
'A'
:
charNo
=
27
;
break
;
case
'b'
:
charNo
=
2
;
break
;
case
'B'
:
charNo
=
28
;
break
;
case
'c'
:
charNo
=
3
;
break
;
case
'C'
:
charNo
=
29
;
break
;
case
'd'
:
charNo
=
4
;
break
;
case
'D'
:
charNo
=
30
;
break
;
case
'e'
:
charNo
=
5
;
break
;
case
'E'
:
charNo
=
31
;
break
;
case
'f'
:
charNo
=
6
;
break
;
case
'F'
:
charNo
=
32
;
break
;
case
'g'
:
charNo
=
7
;
break
;
case
'G'
:
charNo
=
33
;
break
;
case
'h'
:
charNo
=
8
;
break
;
case
'H'
:
charNo
=
34
;
break
;
case
'i'
:
charNo
=
9
;
break
;
case
'I'
:
charNo
=
35
;
break
;
case
'j'
:
charNo
=
10
;
break
;
case
'J'
:
charNo
=
36
;
break
;
case
'k'
:
charNo
=
11
;
break
;
case
'K'
:
charNo
=
37
;
break
;
case
'l'
:
charNo
=
12
;
break
;
case
'L'
:
charNo
=
38
;
break
;
case
'm'
:
charNo
=
13
;
break
;
case
'M'
:
charNo
=
39
;
break
;
case
'n'
:
charNo
=
14
;
break
;
case
'N'
:
charNo
=
40
;
break
;
case
'o'
:
charNo
=
15
;
break
;
case
'O'
:
charNo
=
41
;
break
;
case
'p'
:
charNo
=
16
;
break
;
case
'P'
:
charNo
=
42
;
break
;
case
'q'
:
charNo
=
17
;
break
;
case
'Q'
:
charNo
=
43
;
break
;
case
'r'
:
charNo
=
18
;
break
;
case
'R'
:
charNo
=
44
;
break
;
case
's'
:
charNo
=
19
;
break
;
case
'S'
:
charNo
=
45
;
break
;
case
't'
:
charNo
=
20
;
break
;
case
'T'
:
charNo
=
46
;
break
;
case
'u'
:
charNo
=
21
;
break
;
case
'U'
:
charNo
=
47
;
break
;
case
'v'
:
charNo
=
22
;
break
;
case
'V'
:
charNo
=
48
;
break
;
case
'w'
:
charNo
=
23
;
break
;
case
'W'
:
charNo
=
49
;
break
;
case
'x'
:
charNo
=
24
;
break
;
case
'X'
:
charNo
=
50
;
break
;
case
'y'
:
charNo
=
25
;
break
;
case
'Y'
:
charNo
=
51
;
break
;
case
'z'
:
charNo
=
26
;
break
;
case
'Z'
:
charNo
=
52
;
break
;
default
:
charNo
=
0
;
break
;
//default is charNo=0, this goes into the next 'if' statement
}
if
(
charNo
==
0
)
{
encryptedCharacter
=
theChar
;
System
.
out
.
println
(
"***INVALID CHARACTER*** "
+
encryptedCharacter
);
return
encryptedCharacter
;
//catches if the character is not a letter, and then returns the input value.
}
else
if
(
charNo
<
27
)
//catches if the character is lower case
{
charNo
=
charNo
+
theOffset
;
//applies the offset to the character number
if
(
charNo
>
26
)
//wrapping function, catches if the character number goes "off scale" past 'z'
{
charNo
=
charNo
-
26
;
//wraps the characater number back to the start
}
else
if
(
charNo
<
0
)
{
charNo
=
charNo
+
26
;
}
}
else
{
//handles uppercase characters
charNo
=
charNo
+
theOffset
;
if
(
charNo
>
52
)
//wrapping function for uppercase characters, performs the same function as line 74
{
charNo
=
charNo
-
26
;
}
else
if
(
charNo
<
27
)
{
charNo
=
charNo
+
26
;
}
}
switch
(
charNo
)
//takes the new offset character number, and translates it to its corresponding letter
{
case
1
:
encryptedCharacter
=
'a'
;
break
;
case
2
:
encryptedCharacter
=
'b'
;
break
;
case
3
:
encryptedCharacter
=
'c'
;
break
;
case
4
:
encryptedCharacter
=
'd'
;
break
;
case
5
:
encryptedCharacter
=
'e'
;
break
;
case
6
:
encryptedCharacter
=
'f'
;
break
;
case
7
:
encryptedCharacter
=
'g'
;
break
;
case
8
:
encryptedCharacter
=
'h'
;
break
;
case
9
:
encryptedCharacter
=
'i'
;
break
;
case
10
:
encryptedCharacter
=
'j'
;
break
;
case
11
:
encryptedCharacter
=
'k'
;
break
;
case
12
:
encryptedCharacter
=
'l'
;
break
;
case
13
:
encryptedCharacter
=
'm'
;
break
;
case
14
:
encryptedCharacter
=
'n'
;
break
;
case
15
:
encryptedCharacter
=
'o'
;
break
;
case
16
:
encryptedCharacter
=
'p'
;
break
;
case
17
:
encryptedCharacter
=
'q'
;
break
;
case
18
:
encryptedCharacter
=
'r'
;
break
;
case
19
:
encryptedCharacter
=
's'
;
break
;
case
20
:
encryptedCharacter
=
't'
;
break
;
case
21
:
encryptedCharacter
=
'u'
;
break
;
case
22
:
encryptedCharacter
=
'v'
;
break
;
case
23
:
encryptedCharacter
=
'w'
;
break
;
case
24
:
encryptedCharacter
=
'x'
;
break
;
case
25
:
encryptedCharacter
=
'y'
;
break
;
case
26
:
encryptedCharacter
=
'z'
;
break
;
case
27
:
encryptedCharacter
=
'A'
;
break
;
case
28
:
encryptedCharacter
=
'B'
;
break
;
case
29
:
encryptedCharacter
=
'C'
;
break
;
case
30
:
encryptedCharacter
=
'D'
;
break
;
case
31
:
encryptedCharacter
=
'E'
;
break
;
case
32
:
encryptedCharacter
=
'F'
;
break
;
case
33
:
encryptedCharacter
=
'G'
;
break
;
case
34
:
encryptedCharacter
=
'H'
;
break
;
case
35
:
encryptedCharacter
=
'I'
;
break
;
case
36
:
encryptedCharacter
=
'J'
;
break
;
case
37
:
encryptedCharacter
=
'K'
;
break
;
case
38
:
encryptedCharacter
=
'L'
;
break
;
case
39
:
encryptedCharacter
=
'M'
;
break
;
case
40
:
encryptedCharacter
=
'N'
;
break
;
case
41
:
encryptedCharacter
=
'O'
;
break
;
case
42
:
encryptedCharacter
=
'P'
;
break
;
case
43
:
encryptedCharacter
=
'Q'
;
break
;
case
44
:
encryptedCharacter
=
'R'
;
break
;
case
45
:
encryptedCharacter
=
'S'
;
break
;
case
46
:
encryptedCharacter
=
'T'
;
break
;
case
47
:
encryptedCharacter
=
'U'
;
break
;
case
48
:
encryptedCharacter
=
'V'
;
break
;
case
49
:
encryptedCharacter
=
'W'
;
break
;
case
50
:
encryptedCharacter
=
'X'
;
break
;
case
51
:
encryptedCharacter
=
'Y'
;
break
;
case
52
:
encryptedCharacter
=
'Z'
;
break
;
}
System
.
out
.
println
(
"Plain character: "
+
theChar
+
" Cypher character: "
+
encryptedCharacter
);
return
encryptedCharacter
;
//returns the final result
}
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
...
@@ -26,7 +162,22 @@ public class AssessmentPartThree {
...
@@ -26,7 +162,22 @@ public class AssessmentPartThree {
// Complete this method so that it uses encryptedCharacter to
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
// return the encrypted version of theMessage using theOffset
return
"Encryptred message"
;
char
charCon
=
'a'
;
char
message
[]
=
new
char
[
theMessage
.
length
()];
// sets up a new char array for holding the individual chars from theMessage
for
(
int
i
=
0
;
i
<
theMessage
.
length
();
i
++)
{
char
theChar
=
theMessage
.
charAt
(
i
);
charCon
=
enryptedCharacter
(
theChar
,
theOffset
);
// feeds theChar and theOffset through encryptedCharacter method
message
[
i
]=
charCon
;
// loop iterates through each character in the message and runs it through encryptedCharacter method
}
String
encMessage
=
new
String
(
message
);
//converts the char array to a string
System
.
out
.
println
(
"Plain Text: "
+
theMessage
+
" Cypher Text: "
+
encMessage
);
return
encMessage
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment