-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder documentation.txt
More file actions
104 lines (87 loc) · 2.65 KB
/
encoder documentation.txt
File metadata and controls
104 lines (87 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
FEATURES:
1. Accepts String key input (default = "A")
2. Accepts String plaintext input, case-insensitive, and displays encoded String output.
3. Accepts encoded String input, case-insensitive, and displays decoded String output.
CLASSES:
1. public class Encoder
Attributes:
String plainText
String encodedText
String key
// key.toUpper()
// check key against Cypher.isValidChar()
// If invalid character, deny key value.
Methods:
public String encode (String plainText, String key) {
// Pass key to Cypher.generateCypher() to get encoded cypher table.
// Loop:
// Check if inputs contain characters not in table using Cypher.isValidChar()
// If true, encode normally. If false, add to output String as-is.
return key+encodedText;
}
public String decode (String encodedText, String key) {
// Converts encodedText to plainText using Cypher class.
// Loop:
// Check if inputs contain characters not in table using Cypher.isValidChar()
// If true, decode normally. Else, add to output String as-is.
return plainText;
}
2. public class Cypher
Attributes:
String key
static final String tableDefault //initialised
String tableEncoded
Methods:
boolean isValidChar (String inputChar) {
// Check if tableDefault.contains(inputChar)
return boolean;
}
String generateCypher (String key) {
// Generates tableEncoded String
// Find offset 'distance' by locating index of given key (case-insensitive) within tableDefault.
// Clone tableDefault. Slice length of offset from end of clone table and reattach it to the beginning.
return tableEncoded;
}
==========
TEST CASES:
1a. // Normal encode function 1
Inputs:
key: "B"
plainText: "HELLO WORLD"
Expected output: "BGDKKN VNQKC"
1b. // Normal encode function 2
Inputs:
key: "Q"
plainText: "HELLO WORLD"
Expected output: "Q96++. G.B+5"
2. // Case-insensitivity
Inputs:
key: "b"
plainText: "hello world"
Expected output: "BGDKKN VNQKC"
3. // Invalid chars in plainText input
Inputs:
key: "A"
plainText: "!@#$%^&"
Expected output: "A!@#$%^&"
4. // Invalid key input
Inputs:
key: "?"
plainText: "HELLO WORLD"
Expected output: "Error: Invalid key."
5a. // Normal decode function 1
Inputs:
encodedText: "BGDKKN VNQKC"
Expected output: "HELLO WORLD"
5b. // Normal decode function 2
Inputs:
encodedText: "Q96++. G.B+5"
Expected output: "HELLO WORLD"
6. // Invalid chars in encodedText key
Inputs:
encodedText: "!@#$%^&"
Expected output: "Error: Invalid message format."
7. // Invalid chars in encodedText message body
Inputs:
encodedText: "A@#$%^&"
Expected output: "@#$%^&"