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

Method randomizeSlopeValue

src/Encoder/AffineCipher.js:204–217  ·  view source on GitHub ↗

* Generates a random slope setting value. * @protected * @param {Random} random Random instance * @param {Setting} setting Setting instance * @return {string} Random slope setting value

(random, setting)

Source from the content-addressed store, hash-verified

202 * @return {string} Random slope setting value
203 */
204 randomizeSlopeValue (random, setting) {
205 const alphabetSetting = this.getSetting('alphabet')
206 if (alphabetSetting.isValid()) {
207 const alphabet = alphabetSetting.getValue()
208 const m = alphabet.getLength()
209
210 // Create range based on alphabet and filter coprime values
211 // Don't use caesar cipher slope (a=1) if possible
212 const range = alphabet.getCodePoints().map((_, i) => i + 1)
213 const coprimes = range.filter(a => a > 1 && MathUtil.isCoprime(a, m))
214 return coprimes.length > 0 ? random.nextChoice(coprimes) : 1
215 }
216 return null
217 }
218
219 /**
220 * Generates a random intercept setting value.

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected