Affine module¶
-
class
ciphers.Affine.
Affine
[source]¶ Bases:
flask_restful.Resource
A Simple Affine Cipher. y = mx+b
-
check_coprime
(proposed_value, modolus)[source]¶ Could just have a list of values but check if the user provided value is coprime with 26.
Parameters: - proposed_value – The user provided value
- modolus – Constant value of 26.
Returns: None if it is coprime otherwise an error message with coprime value.
-
decode
(encoded, inverse, b)[source]¶ Decode the selected character based off the intercept and coefficient. unencoded = inverse *(encoded -m)yt
-
encoded
¶ The user’s message encoded
-
inverse
¶ The inverse of the coefficient.
-
b
¶ The intercept value.
-
Return
¶ The decoded value of the given character.
-
-
egcd
(a, b)[source]¶ Extended Euclidean algorithm .. attribute:: a
The selected number-
b
The selected modulus
Returns: The Greatest Common Denominator. -
-
encode
(user_input, m, b)[source]¶ Encode the selected character based off the intercept and coefficient. .. attribute:: user_input
The user’s message-
m
¶ The coefficient of the picked character
-
b
The intercept value.
-
Return
The encoded value of the given character.
-
-
methods
= {'GET'}¶
-
modinv
(a, m)[source]¶ https://stackoverflow.com/questions/4798654/modular-multiplicative-inverse-function-in-python This is to find the multiplicative inverse in order to check if the user provided value is coprime. It only exists when the gcd of a,m are 1.
-
a
¶ The selected number
-
m
The selected modulus,26 is the default here.
Returns: None or the multiplicative inverse of the selected number. -
-