------- Forwarded message -------
From: "David R. Kohel" <[EMAIL PROTECTED]>
To: "Timothy Clemans" <[EMAIL PROTECTED]>
Cc: "William Stein" <[EMAIL PROTECTED]>
Subject:
Date: Sun, 21 Jan 2007 15:44:37 -0800
Dear Timothy,
I hope this answers your two questions:
> How do I encode a character in a string based on position and length of
> message?
The Vigenere cryptosystem is a classical "polyalphabetic" substitution
crytosystem which applies a different cipher to indices in each arithmetic
progression modulo m (of the form i + j*m). To take your example:
sage: S = AlphabeticStrings()
sage: m = S("THEAMERICANGOVERNMENTISWATCHINGYOU")
sage: V = VigenereCryptosystem(S,17)
sage: K = V.random_key()
sage: K
NHLMSYKIMXKVBEAXS
sage: e = V(K)
sage: e(m)
GOPMECBQOXXBPZEOFZLYFAQGIFZRDOKYLM
At the i-th position it applies the i%17-th translation substitution
cipher determined by the key K (i.e. addition of characteris mod 26).
I haven't implemented the Vigenere cryptosystem in full generality,
which would allow an m-tuple of arbitrary substitutions.
Another way to change the cipher by index, is to apply a block cipher
"mode of operation", but I haven't implemented these into the crypto
package.
I have focused on classical cryptosystems, which where actually used,
and which can now be quite easily broken (although when composed they
actually can become much stronger).
Another classical cryptosystem which can be interpretted as a sequence
of substitution ciphers is an Enigma rotor machine. It would not be
hard to implement this in SAGE.
> How do I go from A through Z to the standard 256 characters?
To recover the standard Python string type from an alphabetic string, you
can use 'str' together with the fact that characters print as A, B, C, etc.
sage: ABCD = [ str(S.gen(i)) for i in range(4) ]
sage: ABCD
['A', 'B', 'C', 'D']
or you have used this constructor:
sage: ABCD == [ str(S([i])) for i in range(4) ]
True
The "correct" way provided to do this is to use the encoding and decoding
member function:
sage: A = S.encoding('A')
sage: A
A
sage: A.decoding()
'A'
In particular,
sage: AZ = [ S([i]).decoding() for i in range(26) ]
gives the 26-character alphabet as Python strings.
The "classical" crypto alphabet converts a-z to A-Z and removes all other
characters, thus S.encoding('abcd') gives ABCD, which decodes back to
'ABCD' rather than 'abcd'.
Best regards,
David
------- Forwarded Message
From: "Timothy Clemans" <[EMAIL PROTECTED]>
To: "William Stein" <[EMAIL PROTECTED]>
Subject: Crypto in Sage
Date: Fri, 19 Jan 2007 21:09:56 -0800
Stein,
I have done some work on simple crypto in Sage at
http://sage.math.washington.edu:8101/CRYPTO
I like the results. How do I go from A through Z to the standard 256
characters? How do I encode a character in a string based on position
and length of message?
------- End of Forwarded Message
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---