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

Method performDecode

src/Encoder/RailFenceCipher.js:90–115  ·  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

88 * @return {number[]|string|Uint8Array|Chain} Decoded content
89 */
90 performDecode (content) {
91 const { key: rows, offset } = this.getSettingValues()
92 const length = content.getLength()
93
94 // Cycle after which fence matrix repeats
95 const cycle = rows * 2 - 2
96
97 // Create result array of code points
98 const result = new Array(length)
99
100 let j = -1
101 let x, y
102
103 // Go through virtual matrix rows (y) and cols (x)
104 for (y = 0; y < rows; y++) {
105 for (x = 0; x < length; x++) {
106 // Check if the current x-y-position is situated on the zigzag fence
107 if ((y + x + offset) % cycle === 0 || (y - x - offset) % cycle === 0) {
108 // Set result for the current x-position
109 result[x] = content.getCodePointAt(++j)
110 }
111 }
112 }
113
114 return result
115 }
116}

Callers

nothing calls this directly

Calls 3

getSettingValuesMethod · 0.80
getCodePointAtMethod · 0.80
getLengthMethod · 0.45

Tested by

no test coverage detected