Hackerman, we need your help. We intercepted correspondence between "the bad guys". We need an app able to both decrypt and encrypt files using ROT13 cipher, Morse code and Rail-fence cipher.
You'll have to:
- OOP in PHP
- how to think in algorithms,
- handle edge cases and exceptions,
- read from files,
- use multidimensional arrays.
-
In
Enigma
we useArgsParser
class to encapsulate passed parameters. Finish implementation ofArgsParser
.- Data is extracted from the given string array
- Fields in
ArgsParser
areNULL
if no value was provided
-
Implement the
CipherFactory
class with a factory method that providesCipher
implementations. It must work for all ciphers (ROT13, Rail-fence and Morse code).- Method
isCipherAvailable()
returnstrue
if passed name of a supported cipher,false
otherwise - Method
getCipherForArgs()
returns properCipher
instance. If not possible, or invalid key for specific cipher was provided,EnigmaException
is thrown
- Method
-
Implement execution engine in
Enigma
that interprets and executes meaningful commands and displays messages for all cases- App prints help menu when passed no arguments, or when the first one is
'-h'
- Providing mode different than
'-h'
,'-e'
, or'-d'
leads toEnigmaException
- Providing too few arguments leads to
EnigmaException
. Notice that using'-h'
doesn't need any further arguments - Providing a not supported cipher name leads to
EnigmaException
- Providing non-existent file path leads to
EnigmaException
- All
EnigmaException
s are caught and their messages are printed to the standard output - Method
handleCipherOperation()
encrypts/decrypts file content using the cipher provided byCipherFactory
, and prints the result
- App prints help menu when passed no arguments, or when the first one is
-
Implement ROT13 cipher encrypt and decrypt methods. Upper case letters should appear AFTER lower case ones (see examples below). Create functions
encryptLetter(char)
anddecryptLetter(char)
that will do the mapping of single characters. Methodsencrypt(String)
anddecrypt(String)
will map entire texts. Examples:
encryptLetter('a') -> 'n'
encryptLetter('l') -> 'y'
encryptLetter('m') -> 'z'
encryptLetter('n') -> 'A'
encryptLetter('o') -> 'B'
decryptLetter('C') -> 'p'
decryptLetter('D') -> 'q'
- All alphabetic characters are encrypted
- All alphabetic characters are decrypted
- Non-alphabetic characters are unchanged
- Implement Morse code encryption and decryption. Implementation must support 26 English letters
A
throughZ
and Arabic numerals0
to9
. Convert spaces into word separators ('/'
). Every other symbol has to be omitted.
encode("Hello, World!") -> ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."
decode(".... . .-.. .-.. --- / .-- --- .-. .-.. -..") -> "HELLO WORLD"
- Message gets encrypted into Morse code using word separators
- Non-alphanumeric characters are omitted from the encrypted message
- Message gets decrypted using uppercase letters
- Implement Rail-fence cipher encryption and decryption. Encrypted message should contain all non alphanumeric characters, letters must stay the same (don't change the case)
encrypt("Hello World!") -> "Horel ol!lWd" // key = 3
decrypt("Horel ol!lWd") -> "Hello World!"
- Message gets encrypted
- Letter cases are unchanged
- Message gets decrypted
None