Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment 3
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
daniel.parker
Assessment 3
Commits
f00b680b
Commit
f00b680b
authored
Jan 03, 2019
by
Danie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final commit.
parent
402af014
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
AssessmentPartThree.java
src/AssessmentPartThree.java
+14
-12
No files found.
src/AssessmentPartThree.java
View file @
f00b680b
...
...
@@ -14,21 +14,22 @@ public class AssessmentPartThree {
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
{
char
returnChar
=
theChar
;
int
x
=
0
;
String
alphabet
=
"abcdefghijklmnopqrstuvwxyz"
;
String
alphabet
=
"abcdefghijklmnopqrstuvwxyz"
;
//String containing all the letters of the alphabet.
if
(
Character
.
isUpperCase
(
theChar
))
{
alphabet
=
alphabet
.
toUpperCase
();
alphabet
=
alphabet
.
toUpperCase
();
//If the character is a capital letter then the alphabet string
//becomes upper case to match.
}
for
(
int
i
=
0
;
i
<
alphabet
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
alphabet
.
length
();
i
++)
{
//Increments through every letter of the alphabet.
char
character
=
alphabet
.
charAt
(
i
);
if
(
character
==
theChar
)
{
x
=
i
+
theOffset
;
if
(
character
==
theChar
)
{
//if that letter of the alphabet is the same as the character then..
x
=
i
+
theOffset
;
//that character is then moved by the offset.
if
(
x
>
26
)
{
x
=
(
x
-
26
);
x
=
(
x
-
26
);
// if the offset goes outside of the alphabet then it loops back round the the start.
}
if
(
x
<
0
)
{
x
=
(
x
+
26
);
x
=
(
x
+
26
);
// if the offset goes backwards lower than A then it loops to the end of the alphabet.
}
returnChar
=
alphabet
.
charAt
(
x
);
returnChar
=
alphabet
.
charAt
(
x
);
//Returns the encrypted character.
}
}
...
...
@@ -45,13 +46,14 @@ public class AssessmentPartThree {
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
{
String
alphabet
=
"abcdefghijklmnopqrstuvwxyz"
;
String
codedString
=
""
;
char
[]
theMessageChars
=
theMessage
.
toCharArray
();
String
codedString
=
""
;
//Sets up an empty string to be filled later.
char
[]
theMessageChars
=
theMessage
.
toCharArray
();
//Converts theMessage to a character array.
int
x
=
-
1
;
for
(
int
i
=
0
;
i
<
theMessage
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
theMessage
.
length
();
i
++)
{
//Increments through theMessage character by character.
char
character
=
theMessage
.
charAt
(
i
);
codedString
+=
enryptedCharacter
(
character
,
theOffset
);
codedString
+=
enryptedCharacter
(
character
,
theOffset
);
//recalls the previous method to encrypt each character
//and then adds those characters into the empty string and returns the encrypted message.
}
return
codedString
;
...
...
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