# How to mod a decimal

• Oct 2nd 2011, 04:27 PM
Rapid_W
How to mod a decimal
After decrypting an affine cypher I was left with the inverse encoder of $\frac{i - 2}{5}$ with i being the particular letter of the alphabet with $a:=0$ up to $z:=25$

Take S for example, which decodes to Y, but $\frac{18-2}{5} = 3.2 = 24$ $mod$ $26$

My work around.

$18 + 4\times 26 = 122$
$122 - 2 = 120$
$\frac{120}{5} = 24$

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.
• Oct 3rd 2011, 07:56 AM
Deveno
Re: How to mod a decimal
it depends on what you're "dividing by".

if you are dividing by a number that is co-prime 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 trial-and-error is required here, you just calculate (i - 2)(21), and reduce it mod 26.
• Oct 3rd 2011, 08:19 AM
Rapid_W
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.