
How to mod a decimal
After decrypting an affine cypher I was left with the inverse encoder of with i being the particular letter of the alphabet with up to
Take S for example, which decodes to Y, but
My work around.
I don't know how to change decimals into a mod whole number. My get around was to keep adding 26 to i until I got a number ending in 2 or 7 so i could take 2 and divide by 5 and keep in the integers. Obviously this is a rather long winded way of doing it and it is using my inteligence rather than a algorithm a computer can do. I assume there must be a proper way of doing it but I can't find any info on it.
Thank you.

Re: How to mod a decimal
it depends on what you're "dividing by".
if you are dividing by a number that is coprime to your modulus, then what you are really doing is finding the inverse of the denominator (mod n).
in this case, you are dividing by 5, and (5,26) = 1. thus 5 is invertible (mod 26).
it turns out that 1/5 (mod 26) is 21: 5*21 = 105 = 4(26) + 1.
so 16/5 (mod 26) is 16*21 = 336 = 24 (mod 26). no trialanderror is required here, you just calculate (i  2)(21), and reduce it mod 26.

Re: How to mod a decimal
Thank you, this solves my problem perfectly. I was using the multiplicative inverse trick already to solve the simultaneous equations, i'm not really sure why it didn't click i could use it here as well, it was past my bedtime to be fair.
Also sorry, for putting it in the wrong forum, i put it in discrete as this is currently being covered in my discrete math module.