Hi folks, google has failed me, so I am requesting the assistance of the Ars faithful. I am looking for an algorithm for the decryption of data encoded using an affine cypher.
i.e. E(x) = (ax+b)%n, where a,b<n and gcd[a,n)=1. n being the length of the alphabet in question.
is the encryption formula.
I found out that the formula for decryption is:
x = (ainverse.(E(x) - b))%n
But this makes no sense in my head, as E(x)-b could easily be negative, which to me throws out the whole thing. Am I supposed to just cast out the negativity when modding by n?
Also, I have an algorithm for calculating ainverse, but it doesn't seem to work all the time, sometimes it produces wildly negative answers, which make no sense. Will this happen if I try to find ainverse when gcd(a,n) is not 1?
I understand that not everyone is gonna know what I'm on about, but I'm really struggling to get to grips with this, if anyone's done affine decryption before, could they verify what I've found, and dissuage my fears that it's all gonna go pear shaped?
i.e. E(x) = (ax+b)%n, where a,b<n and gcd[a,n)=1. n being the length of the alphabet in question.
is the encryption formula.
I found out that the formula for decryption is:
x = (ainverse.(E(x) - b))%n
But this makes no sense in my head, as E(x)-b could easily be negative, which to me throws out the whole thing. Am I supposed to just cast out the negativity when modding by n?
Also, I have an algorithm for calculating ainverse, but it doesn't seem to work all the time, sometimes it produces wildly negative answers, which make no sense. Will this happen if I try to find ainverse when gcd(a,n) is not 1?
I understand that not everyone is gonna know what I'm on about, but I'm really struggling to get to grips with this, if anyone's done affine decryption before, could they verify what I've found, and dissuage my fears that it's all gonna go pear shaped?