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
Hide 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
{
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
// letter that that number of places away from it.
// Caeser's Cipher)
// So if an offset value of 1 is chosen, each letter is replaced by the one after it
// An offset value is chosen to encrypt a message. Each letter is replaced by
// - so a becomes b, b becomes c, etc
// the
// If a value of -2 is chosen a becomes y, b becomes z and so on
// 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
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
// after it
{
// - so a becomes b, b becomes c, etc
// 05 - encryptedCharacter
// If a value of -2 is chosen a becomes y, b becomes z and so on
// Complete this method so that it returns the encrypted character for
// theChar when and offset of theOffset is used
public
char
enryptedCharacter
(
char
theChar
,
int
theOffset
)
{
// So if theChar='m' and theOffset is 3 the method will return 'p'
// 05 - encryptedCharacter
// Lower case characters remain lower case, upper case remain upper case
// Complete this method so that it returns the encrypted character for
// Any other characters are returned unchanged
// theChar when and offset of theOffset is used
// So if theChar='m' and theOffset is 3 the method will return 'p'
return
'a'
;
// Lower case characters remain lower case, upper case remain upper case
}
// Any other characters are returned unchanged
char
Encrypted
=
0
;
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
{
if
(
Character
.
isDigit
(
theChar
))
{
// checks to see if a character of theChar is a number
// 06 - encryptedMessage
return
theChar
;
// if it isn't fully made of letters it returns the original value of theChar
// Complete this method so that it uses encryptedCharacter to
}
else
{
// if it was fully letters it goes to this
// return the encrypted version of theMessage using theOffset
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)
return
"Encryptred message"
;
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
}
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