Skip to content

Instantly share code, notes, and snippets.

@ordovician
Last active October 3, 2018 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ordovician/8356480 to your computer and use it in GitHub Desktop.
Save ordovician/8356480 to your computer and use it in GitHub Desktop.
[CongruenceModulo] Functions I made for solving problems in the Khan Academy excercises on Congruence Modulo. Usefull stuff to understand when learning about cryptograpy, like the RSA algorithm used in SSL/TSL as used in HTTPS. If two values A and B gives the same result when doing mod(A, C) and mod(B, C) then they are in the same equivalence cl…
# check if A is congruent to B modulo C.
in_same_equivalence_class(A, B, C) = mod(A, C) == mod(B, C)
# find all X in Xs where X is congruent to B modulo C
function find_numbers_in_same_equivalence_class(A, C, Xs)
r = mod(A, C)
filter(X->mod(X,C) == r, Xs)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment