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

Method performCharEncodeToBlock

src/Encoder/A1Z26.js:67–84  ·  view source on GitHub ↗

* Encodes given character to a block. * @protected * @param {number} codePoint Unicode code point * @param {number} index Unicode code point index * @param {Chain} content Content to be encoded * @return {number[]|string|Uint8Array|Chain|null} Encoded block

(codePoint, index, content)

Source from the content-addressed store, hash-verified

65 * @return {number[]|string|Uint8Array|Chain|null} Encoded block
66 */
67 performCharEncodeToBlock (codePoint, index, content) {
68 const caseSensitivity = this.getSettingValue('caseSensitivity')
69
70 let alphabet = this.getSettingValue('alphabet')
71 if (!caseSensitivity) {
72 alphabet = alphabet.toLowerCase()
73 }
74
75 let charIndex = alphabet.indexOfCodePoint(codePoint)
76 if (charIndex === -1) {
77 return null
78 }
79
80 // This is a 1-based index
81 charIndex += 1
82
83 return charIndex.toString()
84 }
85
86 /**
87 * Decodes given block to a character.

Callers

nothing calls this directly

Calls 4

getSettingValueMethod · 0.80
toLowerCaseMethod · 0.80
indexOfCodePointMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected