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
simon.nutsey
Assessment 3
Commits
36c8fc71
Commit
36c8fc71
authored
Jan 07, 2019
by
simon.nutsey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First commit
parent
e56f0d16
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
3 deletions
+43
-3
AssessmentPartThree.java
src/AssessmentPartThree.java
+43
-3
No files found.
src/AssessmentPartThree.java
View file @
36c8fc71
...
@@ -17,7 +17,34 @@ public class AssessmentPartThree {
...
@@ -17,7 +17,34 @@ 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'
;
String
Lowcase
=
"abcdefghijklmnopqrstuvwxyz"
;
String
Upcase
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
// These strings are used to reference if the characeter is lower or uppercase
char
out
=
theChar
;
//creates an output for the encrypted character
if
(
Character
.
isLowerCase
(
theChar
))
{
//checks the letter to see if it is lowercase
int
index
=
(
Lowcase
.
indexOf
(
theChar
)
+
theOffset
);
//sets the the index of the character
if
(
index
<
0
)
{
out
=
Lowcase
.
charAt
(
26
+
index
);
//if the index is negative count back from z
}
else
if
(
index
>
25
)
{
out
=
Lowcase
.
charAt
(
index
-
26
);
//if the index is more than 25 after z go back to A
}
else
{
out
=
Lowcase
.
charAt
(
index
);
//finds the position of the character and then shifts it by the offset value
}
}
else
if
(
Character
.
isUpperCase
(
theChar
))
{
//checks the letter to see if it is uppercase
int
index
=
(
Upcase
.
indexOf
(
theChar
)
+
theOffset
);
if
(
index
<
0
)
{
out
=
Upcase
.
charAt
(
26
+
index
);
//if the index is negative count back from z
}
else
if
(
index
>
25
)
{
out
=
Upcase
.
charAt
(
index
-
26
);
//if the index is more than 25 after z go back to A
}
else
{
out
=
Upcase
.
charAt
(
index
);
//finds the position of the character and then shifts it by the offset value
}
}
return
out
;
}
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
...
@@ -26,7 +53,20 @@ public class AssessmentPartThree {
...
@@ -26,7 +53,20 @@ 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
[]
outArr
=
new
char
[
theMessage
.
length
()];
//stores the the encrypted message into char
for
(
int
i
=
0
;
i
<
theMessage
.
length
();
i
++)
{
//loops through each letter in the string
outArr
[
i
]
=
enryptedCharacter
(
theMessage
.
charAt
(
i
),
theOffset
);
}
}
String
out
=
new
String
(
outArr
);
//converts the char into to string
return
out
;
}
}
}
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