* Performs encode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain} Encoded content
(content)
| 59 | * @return {number[]|string|Uint8Array|Chain} Encoded content |
| 60 | */ |
| 61 | async performEncode (content) { |
| 62 | // Encode content to coordinates using Polybius square |
| 63 | // As I and J shares the same alphabet position, replace all J chars |
| 64 | const sourcePolybius = await this._polybiusSquare.encode( |
| 65 | content.getString().replace(/j/gi, 'i')) |
| 66 | |
| 67 | // Transpose coordinates such that the first coordinates (X) appear |
| 68 | // combined before the second coordinates (Y) |
| 69 | const polybiusLength = sourcePolybius.getLength() |
| 70 | const resultPolybius = new Array(polybiusLength) |
| 71 | for (let i = 0; i < polybiusLength / 2; i++) { |
| 72 | resultPolybius[i] = |
| 73 | sourcePolybius.getCodePointAt(i * 2) |
| 74 | resultPolybius[polybiusLength / 2 + i] = |
| 75 | sourcePolybius.getCodePointAt(i * 2 + 1) |
| 76 | } |
| 77 | |
| 78 | return this._polybiusSquare.decode(resultPolybius) |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Performs decode on given content. |
nothing calls this directly
no test coverage detected