Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment Part 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
jack.templeman
Assessment Part 3
Commits
8d3e9f2f
Commit
8d3e9f2f
authored
Nov 27, 2018
by
jackt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First Draft
parent
e56f0d16
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
5 deletions
+113
-5
AssessmentPartThree.java
src/AssessmentPartThree.java
+113
-5
No files found.
src/AssessmentPartThree.java
View file @
8d3e9f2f
...
...
@@ -16,8 +16,52 @@ public class AssessmentPartThree {
// So if theChar='m' and theOffset is 3 the method will return 'p'
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
return
'a'
;
int
ascii
=
(
int
)
theChar
;
//converts password char to ascii code to ensure it is part of the allowed character range
int
offsetVal
=
0
;
if
(
ascii
>=
65
&&
ascii
<=
90
||
ascii
>=
97
&&
ascii
<=
122
)
// deduces if the character is between a-z or A-Z
{
if
((
theOffset
<
0
&&
(
ascii
<=
65
-
theOffset
)
&&
(
ascii
>=
65
-
theOffset
))
||
(
theOffset
<
0
&&
(
ascii
<=
97
-
theOffset
)
&&
(
ascii
>=
97
-
theOffset
)))
// if the offset is negative, this accounts for the wraparound
{
offsetVal
=
ascii
-
26
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
return
theChar
;
}
if
((
theOffset
<
0
&&
!(
ascii
<=
65
-
theOffset
&&
ascii
>=
65
-
theOffset
)
||(
theOffset
<
0
&&
!(
ascii
<=
97
-
theOffset
&&
ascii
>=
97
-
theOffset
))))
{
offsetVal
=
ascii
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
return
theChar
;
}
if
((
theOffset
>
0
&&
ascii
>=
90
-
theOffset
&&
ascii
<=
90
-
theOffset
)
||(
theOffset
>
0
&&
ascii
>=
122
-
theOffset
&&
ascii
<=
122
-
theOffset
))
{
offsetVal
=
ascii
-
26
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
return
theChar
;
}
if
((
theOffset
>
0
&&
!(
ascii
>=
90
-
theOffset
&&
ascii
<=
90
-
theOffset
)
||(
theOffset
>
0
&&
!
(
ascii
>=
122
-
theOffset
&&
ascii
<=
122
-
theOffset
))))
{
offsetVal
=
ascii
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
return
theChar
;
}
}
else
{
return
theChar
;
}
return
theChar
;
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
...
...
@@ -25,8 +69,72 @@ public class AssessmentPartThree {
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
String
message
=
""
;
for
(
int
length
=
0
;
length
<
theMessage
.
length
();
length
++)
// for loop to count up through the word length
{
char
theChar
=
theMessage
.
charAt
(
length
);
// selects the letter at the current char placement
String
space
=
Character
.
toString
(
theChar
);
if
(
space
.
equals
(
" "
))
{
message
=
message
+
theChar
;
continue
;
}
int
ascii
=
(
int
)
theChar
;
//converts password char to ascii code to ensure it is part of the allowed character range
int
offsetVal
=
0
;
if
(
ascii
>=
65
&&
ascii
<=
90
||
ascii
>=
97
&&
ascii
<=
122
)
// deduces if the character is between a-z or A-Z
{
if
((
theOffset
<
0
&&
(
ascii
<
65
-
theOffset
)
&&
(
ascii
>=
65
))
||
(
theOffset
<
0
&&
(
ascii
<
97
-
theOffset
)
&&
(
ascii
>=
97
)))
// if the offset is negative, this accounts for the wraparound
{
offsetVal
=
ascii
+
26
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
message
=
message
+
theChar
;
continue
;
}
if
((
theOffset
<
0
&&
!(
ascii
<
65
-
theOffset
&&
ascii
>=
65
)
||(
theOffset
<
0
&&
!(
ascii
<
97
-
theOffset
&&
ascii
>=
97
))))
{
offsetVal
=
ascii
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
message
=
message
+
theChar
;
continue
;
}
if
((
theOffset
>
0
&&
ascii
>
90
-
theOffset
&&
ascii
<=
90
)
||(
theOffset
>
0
&&
ascii
>
122
-
theOffset
&&
ascii
<=
122
))
{
offsetVal
=
ascii
-
26
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
message
=
message
+
theChar
;
continue
;
}
if
((
theOffset
>
0
&&
!(
ascii
>
90
-
theOffset
&&
ascii
<=
90
)
||(
theOffset
>
0
&&
!
(
ascii
>
122
-
theOffset
&&
ascii
<=
122
))))
{
offsetVal
=
ascii
+
theOffset
;
theChar
=
(
char
)
offsetVal
;
message
=
message
+
theChar
;
continue
;
}
if
(!(
ascii
>
64
&&
ascii
<
91
)
||
!(
ascii
>
96
&&
ascii
<
123
))
{
message
=
message
+
theChar
;
continue
;
}
theMessage
=
message
;
}
}
return
message
;
}
return
"Encryptred message"
;
}
}
\ No newline at end of file
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