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

Method decodeCode

src/Encoder/MorseCode.js:380–393  ·  view source on GitHub ↗

* Decodes given code to its character representation. * @protected * @param {string} rawCode Morse code unit * @param {string} shortMark * @param {string} longerMark * @param {string} spaceMark * @return {?string} Character or null, if not defined.

(rawCode, shortMark, longerMark, spaceMark)

Source from the content-addressed store, hash-verified

378 * @return {?string} Character or null, if not defined.
379 */
380 static decodeCode (rawCode, shortMark, longerMark, spaceMark) {
381 // Handle space
382 if (rawCode === spaceMark) {
383 return ' '
384 }
385
386 // Translate marks
387 const code = MorseCodeEncoder.translateMarks(
388 rawCode, [shortMark, longerMark], ['.', '-'])
389
390 // Find code in alphabet
391 const index = codeAlphabet.indexOf(code)
392 return index !== -1 ? alphabet[index] : null
393 }
394
395 /**
396 * Runs from start to end through the string and replaces marks.

Callers 1

performDecodeMethod · 0.80

Calls 2

translateMarksMethod · 0.80
indexOfMethod · 0.80

Tested by

no test coverage detected