performCharTranslate (codePoint, index, content, isEncode) {
    let a = this.getSettingValue('a')
    let b = this.getSettingValue('b')
    let alphabet = this.getSettingValue('alphabet')
    let m = alphabet.getLength()
    let x = alphabet.indexOfCodePoint(codePoint)

    if (x === -1) {
      // character not in alphabet
      if (!this.getSettingValue('includeForeignChars')) {
        // return null character
        return 0
      } else {
        // leave it unchanged
        return codePoint
      }
    }

    let y

    if (isEncode) {
      // E(x) = (ax + b) mod m
      y = MathUtil.mod(a * x + b, m)
    } else {
      // D(x) = (a^-1(x - b)) mod m
      let [c] = MathUtil.xgcd(a, m)
      y = MathUtil.mod(c * (x - b), m)
    }

    return alphabet.getCodePointAt(y)
  }
/**
   * Performs encode or decode on given character, index and content.
   * @protected
   * @param {number} codePoint Unicode code point
   * @param {number} index Unicode code point index inside content.
   * @param {Chain} content Content to be translated.
   * @param {boolean} isEncode True for encoding, false for decoding.
   * @return {number} Resulting Unicode code point
   */
Performs encode or decode on given character, index and content.
@protected
@param {number} codePoint Unicode code point
@param {number} index Unicode code point index inside content.
@param {Chain} content Content to be translated.
@param {boolean} isEncode True for encoding, false for decoding.
@return {number} Resulting Unicode code point
Performs encode or decode on given character index and content . @protected @param { number } codePoint Unicode code point @param { number } index Unicode code point index inside content . @param { Chain } content Content to be translated . @param { boolean } isEncode True for encoding false for decoding . @return { number } Resulting Unicode code point
performCharTranslate (codePoint, index, content, isEncode) {
    let a = this.getSettingValue('a')
    let b = this.getSettingValue('b')
    let alphabet = this.getSettingValue('alphabet')
    let m = alphabet.getLength()
    let x = alphabet.indexOfCodePoint(codePoint)
    if (x === -1) {
      if (!this.getSettingValue('includeForeignChars')) {
        return 0
      } else {
        return codePoint
      }
    }
    let y
    if (isEncode) {
      y = MathUtil.mod(a * x + b, m)
    } else {
      let [c] = MathUtil.xgcd(a, m)
      y = MathUtil.mod(c * (x - b), m)
    }
    return alphabet.getCodePointAt(y)
  }
performCharTranslate ( codePoint , index , content , isEncode ) { let a = this . getSettingValue ( 'a' ) let b = this . getSettingValue ( 'b' ) let alphabet = this . getSettingValue ( 'alphabet' ) let m = alphabet . getLength ( ) let x = alphabet . indexOfCodePoint ( codePoint ) if ( x === - 1 ) { if ( ! this . getSettingValue ( 'includeForeignChars' ) ) { return 0 } else { return codePoint } } let y if ( isEncode ) { y = MathUtil . mod ( a * x + b , m ) } else { let [ c ] = MathUtil . xgcd ( a , m ) y = MathUtil . mod ( c * ( x - b ) , m ) } return alphabet . getCodePointAt ( y ) }
Performs encode or decode on given character, index and content.
Performs encode or decode on given character index and content .
// character not in alphabet // return null character // leave it unchanged // E(x) = (ax + b) mod m // D(x) = (a^-1(x - b)) mod m