This belongs on [sage-support] and thus I'm CCing my answer there (also, David 
Kohel reads [sage-support] IIRC)

This seems to be the right way of doing it:

sage: S = AlphabeticStrings()
sage: E = SubstitutionCryptosystem(S)
sage: K = S('MHKENLQSCDFGBIAYOUTZXJVWPR')
sage: K
MHKENLQSCDFGBIAYOUTZXJVWPR
sage: type(K)
<class 'sage.monoids.string_monoid_element.StringMonoidElement'>

I agree that the difference between the two toplevel imports (or lack thereof) 
is somewhat inconsistent, but I guess the reason is that 
PermutationGroupElements are much more used than StringMonoidElements.

Cheers,
Martin

----------  Forwarded Message  ----------

Subject: import of commands
Date: Monday 23 March 2009
From: Stanislav Bulygin <buly...@mathematik.uni-kl.de>
To: Martin Albrecht <m...@informatik.uni-bremen.de>
...
   I have a question regarding example-commands you have for crypto in  
Sage. Namely, e.g. I want to define a concrete key for the substitution  
cipher:

S = AlphabeticStrings()
E = SubstitutionCryptosystem(S)
K=StringMonoidElement(S,'MHKENLQSCDFGBIAYOUTZXJVWPR')

As such written I obtain an error "NameError: name 'StringMonoidElement'  
is not defined". So I have to do this explicitly

 from sage.monoids.string_monoid_element import StringMonoidElement

Interestingly enough, the following works fine with no further imports:

S = AlphabeticStrings()
E = TranspositionCryptosystem(S,5)
K = PermutationGroupElement('(4,2,5,3,1)')

So is there an inconsistency or is it just as it is? The thing is that I  
need illustrations for the book we are writing (I think you received a  
reply from Stein) and such things as 'from ... import ...' look kind of  
ugly in an example.

Could you please comment on that?

         Yours, Stas.

-------------------------------------------------------

-- 
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF
_www: http://www.informatik.uni-bremen.de/~malb
_jab: martinralbre...@jabber.ccc.de


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to