* Performs encode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain} Encoded content
(content)
| 81 | * @return {number[]|string|Uint8Array|Chain} Encoded content |
| 82 | */ |
| 83 | async performEncode (content) { |
| 84 | const tapMark = this.getSettingValue('tapMark').getString() |
| 85 | const groupMark = this.getSettingValue('groupMark').getString() |
| 86 | const letterMark = this.getSettingValue('letterMark').getString() |
| 87 | |
| 88 | // Encode content to coordinates using Polybius square |
| 89 | // As C and K shares the same alphabet position, replace all K chars |
| 90 | const coordinates = await this._polybiusSquare.encode( |
| 91 | content.getString().replace(/k/gi, 'c')) |
| 92 | |
| 93 | const count = coordinates.getLength() / 2 |
| 94 | let row, column |
| 95 | let result = '' |
| 96 | |
| 97 | // Translate each set of coordinates into tap marks |
| 98 | for (let i = 0; i < count; i++) { |
| 99 | row = parseInt(coordinates.getCharAt(i * 2)) |
| 100 | column = parseInt(coordinates.getCharAt(i * 2 + 1)) |
| 101 | |
| 102 | result += |
| 103 | (i > 0 ? letterMark : '') + |
| 104 | tapMark.repeat(row) + |
| 105 | groupMark + |
| 106 | tapMark.repeat(column) |
| 107 | } |
| 108 | |
| 109 | return result |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Performs decode on given content. |
nothing calls this directly
no test coverage detected