Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AssesmentThree
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
william.hill1
AssesmentThree
Commits
61762793
Commit
61762793
authored
Feb 02, 2019
by
william.hill1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update AssessmentPartThree.java
parent
e56f0d16
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
32 deletions
+53
-32
AssessmentPartThree.java
src/AssessmentPartThree.java
+53
-32
No files found.
src/AssessmentPartThree.java
View file @
61762793
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
// 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 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
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
{
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
char
Encrypted
=
0
;
return
'a'
;
if
(
Character
.
isDigit
(
theChar
))
{
// checks to see if a character of theChar is a number
return
theChar
;
// if it isn't fully made of letters it returns the original value of theChar
}
else
{
// if it was fully letters it goes to this
char
Value
=
(
char
)
(
theChar
+
theOffset
);
// adds theChar value and the offset and sets this as a variable
if
(
Value
>
'z'
)
// if the value of "Value" is more then the ASCII value of 'z'(122)
Encrypted
+=
(
char
)
(
Value
)
-
(
26
-
theOffset
);
// if the value is above the max it -26 to get it back
// to 'a'
// and goes up from there.
else
// if test isn't bigger then 'z'
Encrypted
+=
(
char
)
(
Value
);
// it will just add the offset since the values are in range
}
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
return
"Encryptred message"
;
return
Encrypted
;
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
{
StringBuilder
Encrypted
=
new
StringBuilder
();
// builds the string which will be returned at the end
for
(
char
i
:
theMessage
.
toCharArray
())
{
//sets the value of i to the values in theMessage, in char form
if
(
Character
.
isLetter
(
i
))
{
//chescks to see if the character is a letter
if
(
Character
.
isUpperCase
(
i
))
{
//checks to see if the character is an uppercase letter
Encrypted
.
append
((
char
)
(
'A'
+
(
i
-
'A'
+
theOffset
%
26
+
26
)
%
26
));
// if it is an upercase letter it will change the character like this
}
else
{
// if its not uppercase
Encrypted
.
append
((
char
)
(
'a'
+
(
i
-
'a'
+
theOffset
%
26
+
26
)
%
26
));
//if it is an lowercase letter it will change the character like this
}
}
else
{
//if the character isnt a letter it will leave it unchanged
Encrypted
.
append
(
i
);
}
}
return
Encrypted
.
toString
();
//returns the Array in a stringform
}
}
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