* Performs decode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain} Decoded content
(content)
| 124 | * @return {number[]|string|Uint8Array|Chain} Decoded content |
| 125 | */ |
| 126 | async performDecode (content) { |
| 127 | const { key, groupSize } = this.getSettingValues() |
| 128 | |
| 129 | // Derive mixed-alphabet from key |
| 130 | const alphabet = Chain.wrap(key).extend(baseAlphabet).getCodePoints() |
| 131 | |
| 132 | // Map Unicode code points to their respective alphabet positions |
| 133 | const positions = |
| 134 | content.toLowerCase().getCodePoints() |
| 135 | .map(codePoint => alphabet.indexOf(codePoint)) |
| 136 | .filter(codePoint => codePoint !== -1) |
| 137 | |
| 138 | // Fill in table horizontally |
| 139 | // Refer to the `performEncode` method for more detailed explanations |
| 140 | const length = positions.length |
| 141 | const table = new Array(length * 3) |
| 142 | let i, j, coordinates |
| 143 | |
| 144 | for (i = 0; i < length; i++) { |
| 145 | coordinates = this.cartesianCoordinatesFromIndex(positions[i]) |
| 146 | for (j = 0; j < 3; j++) { |
| 147 | table[i * 3 + j] = coordinates[j] |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // Read trigrams vertically for each character |
| 152 | const result = new Array(length) |
| 153 | let group, index, size |
| 154 | |
| 155 | for (i = 0; i < length; i++) { |
| 156 | // Gather group facts |
| 157 | group = Math.floor(i / groupSize) |
| 158 | index = i - group * groupSize |
| 159 | size = Math.min(groupSize, length - group * groupSize) |
| 160 | |
| 161 | // Read one character from vertical trigram |
| 162 | for (j = 0; j < 3; j++) { |
| 163 | coordinates[j] = table[index + group * groupSize * 3 + size * j] |
| 164 | } |
| 165 | |
| 166 | index = this.indexFromCartesianCoordinates(coordinates) |
| 167 | result[i] = alphabet[index] |
| 168 | } |
| 169 | |
| 170 | return result |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Translates a one-dimensional index to three-dimensional cartesian |
nothing calls this directly
no test coverage detected