Hi David! On Mon, Jan 28, 2013 at 3:05 PM, Aaron Meurer <asmeu...@gmail.com> wrote: > On Mon, Jan 28, 2013 at 3:16 PM, David Joyner <wdjoy...@gmail.com> wrote: >> Hi: >> >> For various reasons, I'm having a hard time using Sage >> when I teach a class in coding theory and cryptography. >> (Mostly, this is because of a lack of support for non-windows >> machines where I teach.) So, I'm trying to find what >> sympy, which is easier to install on windows, can do in terms of >> basic cryptography and basic error-correcting codes. >> My vague memory says the answer is basically nothing, >> and a google search doesn't turn up anything. >> >> Am I missing something? >> >> If not, I plan on writing up something myself. Should it go in >> combinatorics? Or maybe a new module, such as algebra >> or codes or crypto? I would like to implement >> some classical ciphers, such as >> Bifid, >> Caesar/shift, >> Hill (I hope), >> Substitution >> Vigenere >> and some associated algorithms (repeated squaring >> for modular exponentiation, and the extended Euclidean algorithm). > > The algorithms should all be implemented already, but none of the > codes. The algorithms will be in various places, but in general, > check the polys. The extended Euclidean algorithm is gcdex, and works > for polynomials or integers. Modular exponentiation is already > implemented in Python (pow(a, b, c) is (a**b) % c). SymPy Integers > should define the three-arg __pow__ so that this works with them too > (if not, it will be easy to fix). The same for finite field stuff > (FF, see below). > > For the codes, I'm not sure. "combinatorics" already contains a bunch > of stuff that isn't really combinatorics (like group theory). Maybe > we should create "algebra" and put it and group theory there. You > will have a better idea than I about where the best place to put > things is, since you know what things will do. We definitely welcome > the contribution, regardless of where it ends up. I am actually > taking a course in algebraic geometry and codes this semester, > focusing on error-correcting codes, so maybe this will be useful to me > (or maybe not, it sounds like you are focusing more on cryptography > than codes). > >> >> For Hill's cipher, I will need to invert a matrix >> modulo m. I think I can think of a way to do that, with a little >> work (invert over the rationals, find the non-integer terms >> and invert them one at a time), but if anyone knows of a >> short simple implemention in python, please let me know. > > You could probably use the fact that the only number that you have to > invert is the determinant somehow. > > Also, you could try using FF (like FF(3)(1) for 1 mod 3). It seems to > work in my tests. You'll more likely than not want to use FF(3, > symmetric=False) to avoid "negative" numbers.
I would be very happy to test your code if you write any, feel free to ping me anytime. I think that cryptography is an interesting subject, and since I don't know the related math much, it might be a good occasion for me to learn. Ondrej -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.