Encrypt and Decrypt Strings
Problem statement
Build an encrypter from three constructor inputs:
keys[i]is a unique one-character key;values[i]is the two-character encryption for that key; anddictionarycontains valid plaintext words.
Process each row [method, word] in operations:
encrypt: replace every character ofwordwith its mapped two-character value. If any character has no key, the result is the empty string.decrypt: count dictionary entries whose complete encryption equalsword.
Return one string per operation in order. An encryption result is returned directly; a decryption count is returned in decimal form. Different keys may share the same encrypted value.
Function
processEncrypter(keys: String[], values: String[], dictionary: String[], operations: String[][]) → String[]Examples
Example 1
keys = ["a","b","c","d"]values = ["ei","zf","ei","am"]dictionary = ["abcd","acbd","adbc","badc","dacb","cadb","cbda","abad"]operations = [["encrypt","abcd"],["decrypt","eizfeiam"]]return = ["eizfeiam","2"]abcd encrypts to eizfeiam. Exactly abcd and abad in the dictionary produce that ciphertext.
Example 2
keys = ["a","b"]values = ["aa","bb"]dictionary = ["ab","ba"]operations = [["encrypt","ac"],["decrypt","aabb"]]return = ["","1"]The first word contains an unmapped character. Only ab encrypts to aabb.
Constraints
1 <= keys.length == values.length <= 26.- Every key is a distinct lowercase English character represented as a one-character string.
- Every value contains exactly two lowercase English characters; values need not be unique.
1 <= dictionary.length <= 100, and dictionary words contain only lowercase English letters.1 <= operations.length <= 100.- An
encryptword has length at most2000. - A
decryptword has positive even length at most200.