Avril Coghlan <[email protected]> writes:
> Dear Keshav,
>
> Thanks very much, that helps a lot and makes lots of sense now.
>
> Using what you said, I was able to encode 'HAPPYNEWYEAR' using a 1-based 
> system
> (A=1, B=2, C=3,....Z=26) by applying (i) a multiplicative cipher with a=1,b=1
> to change to a 1-based system (ii) then a multiplicative cipher with a=9,b=0,
> (iii) then a multiplicative cipher with a=1,b=25 to change back to the 0-based
> system to get the answer. I did this by typing:
>      A = AffineCryptosystem(AlphabeticStrings())
>      P = A.encoding("HAPPYNEWYEAR"); P
>      a, b = (1, 1) 
>      C = A.enciphering(a, b, P); C
>      a, b = (9, 0)
>      C2 = A.enciphering(a, b, C); C2
>      a, b = (1, 25)
>      C3 = A.enciphering(a, b, C2); C3
> This gives 'TINNQVSYQSIF', which is what I expected.

You could also do the conversion beforehand instead of letting Sage do
it, if you wish:

Let x be the value of a letter according to your desired scheme (A=1,
B=2, etc.). You want it to be transformed into ax + b. Instead, though,
Sage encodes A as 0, B as 1, etc., so the letter it gives you back is
actually a(x-1) + b + 1. Expanding this out, you get ax + (b - a + 1).
So to figure out what a' and b' to call the function with so that you
get back ax + b, just compute:

a = a', b = b' - a + 1

So a' = a, and b' = a - b - 1.

So that's why you were able to get the answer you wanted for (9, 0) by
calling the function with (9, 8); because 9 = 9 and 8 = 9 - 0 - 1.

> Thanks again for your help, I appreciate it a lot.

Sure, glad I could help :)

-Keshav

----
Join us in #sagemath on irc.freenode.net !

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to