Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Part03
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
Assessment
Part03
Commits
f85758b3
Commit
f85758b3
authored
Jan 04, 2019
by
neil.whitehead
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FINAL
parent
ff9e8560
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
AssessmentPartThree.java
src/AssessmentPartThree.java
+24
-24
No files found.
src/AssessmentPartThree.java
View file @
f85758b3
/**
* <b>Assessment</b> part three<br>
* <b>Created</b> 08/11/18<br>
* <b>Modified</b> 04/01/18<br>
* @author <a href = "mailto:neil.whitehead@yorksj.ac.uk"> Neil Whitehead</a>, <a href = "mailto:a.guest@yorksj.ac.uk">Andrew Guest</a>
*/
public
class
AssessmentPartThree
{
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// An offset value is chosen to encrypt a message. Each letter is replaced by the
// letter that that number of places away from it.
// So if an offset value of 1 is chosen, each letter is replaced by the one after it
// - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on
/**
* Descripts characters using Caesar cipher <br>
* Assumes that no validation checks are required.
* @param theChar char
* @param theOffset int
* @return theChar char
*/
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
{
// 05 - encryptedCharacter
// Complete this method so that it returns the encrypted character for
// theChar when and offset of theOffset is used
// 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
{
//Dealing with negative offsets
theOffset
=
(
theOffset
<
0
)
?
26
+
theOffset
:
theOffset
;
//ensures that the offset will
"wrap around" by finding corresponding
positive value
//ensures that the offset will
properly "wrap around" by finding complementary
positive value
//Uppercase characters
if
((
theChar
>=
65
)
&&
(
theChar
<=
90
))
//65 to 90 = A to B
...
...
@@ -40,21 +38,24 @@ public class AssessmentPartThree
( + 97) + ASCII a/A to return result to ASCII char
(char) result needs to be casted to char
*/
return
theChar
;
//any non alphabetical chars will fall through and return original char
}
/**
* Decripts strings using Caesar cipher <br>
* Assumes that no validation checks are required.
* @param theMessage string
* @param theOffset int
* @return chaResultArr string
*/
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
char
chaMessageArr
[]
=
theMessage
.
toCharArray
();
char
[]
chaResultArr
=
new
char
[
chaMessageArr
.
length
];
//initialising Arrays
//initialising Arrays
for
(
int
i
=
0
;
i
<
chaMessageArr
.
length
;
i
++)
//loop to run through each character in encrypted message
...
...
@@ -62,7 +63,6 @@ public class AssessmentPartThree
chaResultArr
[
i
]
=
enryptedCharacter
(
chaMessageArr
[
i
],
theOffset
);
//passing each character to decryption method and saving result in array
}
return
(
new
String
(
chaResultArr
));
//converting result array into string, and returning this
}
...
...
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