Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AssessmentPart3
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
norbert.dajnowski
AssessmentPart3
Commits
3de7a1a4
Commit
3de7a1a4
authored
Nov 23, 2018
by
norbertdajnowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit 1
parent
b9095079
Pipeline
#316
failed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
3 deletions
+47
-3
AssessmentPartThree.java
src/AssessmentPartThree.java
+46
-2
AssessmentPartThreeTest.java
src/AssessmentPartThreeTest.java
+1
-1
No files found.
src/AssessmentPartThree.java
View file @
3de7a1a4
...
...
@@ -17,7 +17,43 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
return
'a'
;
char
encryptedC
=
(
char
)
0
;
if
((
theChar
>
64
)
&&
(
theChar
<
91
))
{
//if statement to check if the character is between A-Z
if
(
theChar
+
theOffset
>
90
)
{
//if the offset goes over Z character
return
encryptedC
=
(
char
)
(((
theChar
+
theOffset
)
-
90
)
+
64
);
//return back to A and add rest of the offset there
}
else
if
(
theChar
+
theOffset
<
65
)
{
//if the offset is negative and goes below A
return
encryptedC
=
(
char
)
(
91
-
(
65
-
(
theChar
+
theOffset
)));
//return to Z and take away rest of the offset
}
//else if the character doesn't cross under A or over Z then add offset to theChar normally
return
encryptedC
=
(
char
)(
theChar
+
theOffset
);
}
if
((
theChar
>
96
)
&&
(
theChar
<
123
))
{
//if statement to check if the character is between a-z
if
(
theChar
+
theOffset
>
122
)
{
//if the offset goes over z character
return
encryptedC
=
(
char
)
(((
theChar
+
theOffset
)
-
122
)
+
96
);
//return back to a and add rest of the offset there
}
else
if
(
theChar
+
theOffset
<
97
)
{
//if the offset is negative and goes below a
return
encryptedC
=
(
char
)
(
123
-
(
97
-
(
theChar
+
theOffset
)));
//return to z and take away rest of the offset
}
return
encryptedC
=
(
char
)(
theChar
+
theOffset
);
}
//else if the character doesn't cross under a or over z then add offset to theChar normally
return
theChar
;
//return theChar unaffectedly if it is not a character A-Z or a-z
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
...
...
@@ -26,7 +62,15 @@ public class AssessmentPartThree {
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
return
"Encryptred message"
;
String
EncryptedS
=
""
;
//string for the final cipher-text
for
(
int
i
=
0
;
i
<=
theMessage
.
length
()
-
1
;
i
++)
{
//iterate through all characters in the message
EncryptedS
=
EncryptedS
+
enryptedCharacter
(
theMessage
.
charAt
(
i
),
theOffset
);
//add encrypted character onto the end of EncryptedS, using the enryptedCharacter method
}
return
EncryptedS
;
//return the encrypted message
}
}
src/AssessmentPartThreeTest.java
View file @
3de7a1a4
...
...
@@ -34,7 +34,7 @@ class AssessmentPartThreeTest {
@CsvSource
({
"hello,5,mjqqt"
,
"Java Coding,-3,Gxsx Zlafkd"
,
"dandelion,8,livlmtq
m
v"
,
"dandelion,8,livlmtq
w
v"
,
"ktixevzout,-6,encryption"
})
void
testEncryptedString
(
String
theMessage
,
int
theOffset
,
String
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