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

Method performEncode

src/Encoder/BifidCipher.js:61–79  ·  view source on GitHub ↗

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

(content)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 5

encodeMethod · 0.80
getStringMethod · 0.80
getCodePointAtMethod · 0.80
decodeMethod · 0.80
getLengthMethod · 0.45

Tested by

no test coverage detected