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

Method performTranslate

src/Encoder/BitwiseOperation.js:81–95  ·  view source on GitHub ↗

* Performs encode or decode on given content. * @protected * @param {Chain} content * @param {boolean} isEncode True for encoding, false for decoding * @return {number[]|string|Uint8Array|Chain|Promise} Resulting content

(content, isEncode)

Source from the content-addressed store, hash-verified

79 * @return {number[]|string|Uint8Array|Chain|Promise} Resulting content
80 */
81 performTranslate (content, isEncode) {
82 const bytes = content.getBytes()
83 const operandBytes = this.getSettingValue('operand')
84 let operation = this.getSettingValue('operation')
85
86 if (!isEncode) {
87 // Inverse operation
88 operation = operationInverseMap[operation]
89 }
90
91 // Perform operation on each byte
92 return bytes.map((byte, index) =>
93 this.performByteOperation(byte, operation,
94 operandBytes[index % operandBytes.length]))
95 }
96
97 /**
98 * Performs given bitwise operation on a single byte.

Callers

nothing calls this directly

Calls 3

performByteOperationMethod · 0.95
getBytesMethod · 0.80
getSettingValueMethod · 0.80

Tested by

no test coverage detected