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

Method validateSlopeValue

src/Encoder/AffineCipher.js:176–195  ·  view source on GitHub ↗

* Validates slope (a) setting value. * @param {number} a * @return {boolean|object}

(a)

Source from the content-addressed store, hash-verified

174 * @return {boolean|object}
175 */
176 validateSlopeValue (a) {
177 const alphabetSetting = this.getSetting('alphabet')
178 if (!alphabetSetting.isValid()) {
179 // Can't validate slope without valid alphabet setting
180 return false
181 }
182
183 // The value a must be chosen such that a and m are coprime
184 const m = alphabetSetting.getValue().getLength()
185 if (!MathUtil.isCoprime(a, m)) {
186 return {
187 key: 'affineCipherFunctionInvalid',
188 message:
189 'The value must be chosen such that it is coprime to the size ' +
190 `of the alphabet (${m})`
191 }
192 }
193
194 return true
195 }
196
197 /**
198 * Generates a random slope setting value.

Callers

nothing calls this directly

Calls 5

getSettingMethod · 0.80
isCoprimeMethod · 0.80
isValidMethod · 0.45
getLengthMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected