Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Assignment 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
bran.harvey-chadwi
Java Assignment 3
Commits
51ae5ee1
Commit
51ae5ee1
authored
Nov 29, 2018
by
Karrthus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Completed futher work
parent
5bcb98a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
17 deletions
+71
-17
AssessmentPartThree.java
src/AssessmentPartThree.java
+70
-16
AssessmentPartThreeTest.java
src/AssessmentPartThreeTest.java
+1
-1
No files found.
src/AssessmentPartThree.java
View file @
51ae5ee1
public
class
AssessmentPartThree
{
public
class
AssessmentPartThree
{
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// 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
// An offset value is chosen to encrypt a message. Each letter is replaced by the
// letter that that number of places away from it.
// letter that that number of places away from it.
...
@@ -8,7 +9,9 @@ public class AssessmentPartThree {
...
@@ -8,7 +9,9 @@ public class AssessmentPartThree {
// - so a becomes b, b becomes c, etc
// - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on
// 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
// 05 - encryptedCharacter
// Complete this method so that it returns the encrypted character for
// Complete this method so that it returns the encrypted character for
...
@@ -16,8 +19,9 @@ public class AssessmentPartThree {
...
@@ -16,8 +19,9 @@ public class AssessmentPartThree {
// So if theChar='m' and theOffset is 3 the method will return 'p'
// So if theChar='m' and theOffset is 3 the method will return 'p'
// Lower case characters remain lower case, upper case remain upper case
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
// Any other characters are returned unchanged
String
lowerbet
=
"abcdefghijklmnopqrstuvwxyz"
;
String
lowerbet
=
"abcdefghijklmnopqrstuvwxyz"
;
String
capitalbet
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
String
capitalbet
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
for
(
int
i
=
0
;
i
<
lowerbet
.
length
();
i
++)
for
(
int
i
=
0
;
i
<
lowerbet
.
length
();
i
++)
...
@@ -29,21 +33,24 @@ public class AssessmentPartThree {
...
@@ -29,21 +33,24 @@ public class AssessmentPartThree {
char
newnumber
=
lowerbet
.
charAt
(
theOffset
+
i
);
char
newnumber
=
lowerbet
.
charAt
(
theOffset
+
i
);
return
newnumber
;
return
newnumber
;
}
}
if
(
theChar
==
capitalbet
.
charAt
(
i
))
{
char
newnum
=
lowerbet
.
charAt
(
theOffset
+
i
);
return
newnum
;
}
if
(
theChar
==
capitalbet
.
charAt
(
i
))
{
char
newnumber
=
capitalbet
.
charAt
(
theOffset
+
i
);
return
newnumber
;
}
}
char
newnumber
=
theChar
;
char
newnumber
=
theChar
;
return
newnumber
;
return
newnumber
;
}
}
}
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
public
String
encryptedString
(
String
theMessage
,
int
theOffset
)
...
@@ -51,8 +58,55 @@ public class AssessmentPartThree {
...
@@ -51,8 +58,55 @@ public class AssessmentPartThree {
// 06 - encryptedMessage
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
// return the encrypted version of theMessage using theOffset
return
"Encryptred message"
;
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
String
alphabeto
=
"abcdefghijklmnopqrstuvwxyz"
;
String
CAPSalphabet
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
char
newnum
=
0
;
char
[]
theChar
=
theMessage
.
toCharArray
();
for
(
int
x
=
0
;
x
<
theMessage
.
length
();
x
++)
{
for
(
int
i
=
0
;
i
<
alphabeto
.
length
();
i
++)
{
if
(
theChar
[
x
]
==
alphabeto
.
charAt
(
i
))
{
newnum
=
alphabeto
.
charAt
(
theOffset
+
i
);
}
if
(
theChar
[
x
]
==
CAPSalphabet
.
charAt
(
i
))
{
newnum
=
CAPSalphabet
.
charAt
(
theOffset
+
i
);
}
}
theChar
[
x
]
=
newnum
;
System
.
out
.
println
(
theChar
[
x
]);
}
String
output
=
Arrays
.
toString
(
theChar
);
System
.
out
.
println
(
output
);
return
"Encryptred message"
;
}
}
}
}
}
}
src/AssessmentPartThreeTest.java
View file @
51ae5ee1
...
@@ -26,7 +26,7 @@ class AssessmentPartThreeTest {
...
@@ -26,7 +26,7 @@ class AssessmentPartThreeTest {
"T,-7,M"
"T,-7,M"
})
})
void
testEnryptedCharacter
(
char
theChar
,
int
theOffset
,
char
encChar
)
{
void
testEnryptedCharacter
(
char
theChar
,
int
theOffset
,
char
encChar
)
{
assertEquals
(
encChar
,
test
.
enryptedCharacter
(
theChar
,
theOffset
));
assertEquals
(
encChar
,
test
.
enryptedCharacter
(
theChar
,
theOffset
));
}
}
@ParameterizedTest
@ParameterizedTest
...
...
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