MCPcopy Create free account
hub / github.com/cryptii/cryptii / performDecode

Method performDecode

src/Encoder/TapCode.js:118–148  ·  view source on GitHub ↗

* Performs decode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain} Decoded content

(content)

Source from the content-addressed store, hash-verified

116 * @return {number[]|string|Uint8Array|Chain} Decoded content
117 */
118 performDecode (content) {
119 const tapMark = this.getSettingValue('tapMark').getCodePoints()
120 const tapMarkLength = tapMark.length
121 const input = content.getCodePoints()
122
123 let coordinates = ''
124 let i = 0
125 let j = -1
126 let value = 0
127
128 // Iterate through tap marks
129 while ((j = ArrayUtil.indexOfSlice(input, tapMark, j + 1)) !== -1) {
130 // Check if the current dot is adjacent to the previous one
131 if (i === 0 || j === i + tapMarkLength) {
132 // Increase current coordinate value
133 value++
134 } else {
135 // Append coordinate
136 coordinates += value.toString()
137 value = 1
138 }
139
140 i = j
141 }
142
143 // Append last coordinate
144 coordinates += value.toString()
145
146 // Decode coordinates using Polybius square
147 return this._polybiusSquare.decode(coordinates)
148 }
149}

Callers

nothing calls this directly

Calls 5

getCodePointsMethod · 0.80
getSettingValueMethod · 0.80
indexOfSliceMethod · 0.80
toStringMethod · 0.80
decodeMethod · 0.80

Tested by

no test coverage detected