public class Encrypt
extends java.lang.Object
The provided code is incomplete. Modify it so that it works properly and passes the unit tests in
EncryptTest.java
.
Modifier and Type | Field | Description |
---|---|---|
static int |
MAX_SHIFT |
Maximum shift that encrypt and decrypt need to handle.
|
static int |
MIN_SHIFT |
Minimum shift that encrypt and decrypt need to handle.
|
static int |
TRANSFORM_END |
Transformation end.
|
static int |
TRANSFORM_MODULUS |
Modulo to use for our transformation.
|
static int |
TRANSFORM_START |
Transformation start.
|
Constructor | Description |
---|---|
Encrypt() |
Modifier and Type | Method | Description |
---|---|---|
static char[] |
decrypt(char[] line,
int shift) |
Decrypt a single line of text using a rotate-N transformation.
|
static char[] |
encrypt(char[] line,
int shift) |
Encrypt a single line of text using a rotate-N transformation.
|
static void |
main(java.lang.String[] unused) |
Solicits a single line of text from the user, encrypts it using a random shift, and then
decrypts it.
|
public static final int MIN_SHIFT
public static final int MAX_SHIFT
public static final int TRANSFORM_START
public static final int TRANSFORM_END
public static final int TRANSFORM_MODULUS
public static char[] encrypt(char[] line, int shift)
The printable range of ASCII characters starts at decimal value 32 (' ') and ends at 126 ('~'). You should shift characters within this range by the shift value provided. For example, ' ' (32) shift 1 becomes '!' (33), while '~' (126) shift 1 wraps around and becomes ' ' (32). You may want to explore modular arithmetic to simplify the transformation.
Your function should return a new character array, not modify the one that it is passed.
Both encrypt and decrypt may receive invalid inputs. If the character array contains invalid characters (outside of the range defined above), or if the shift value is outside the range defined above (e.g., larger than MAX_SHIFT), you should return null.
Your solution must match the expected output exactly, otherwise you will not receive credit.
Complete the Javadoc comment for this function and write it.
line
- array of characters to encryptshift
- amount to shift each characterpublic static char[] decrypt(char[] line, int shift)
See comment for encrypt above.
line
- array of characters to decryptshift
- amount to shift each characterpublic static void main(java.lang.String[] unused)
You are free to review this function, but should not modify it. Note that this function is not tested by the test suite, as it is purely to aid your own interactive testing.
unused
- unused input arguments