Module: sage.crypto.classical_cipher
Classical Ciphers.
Class: HillCipher
self, parent, key) |
Create a Hill cipher.
Input: parent and key
sage: S = AlphabeticStrings() sage: E = HillCryptosystem(S,3) sage: E Hill cryptosystem on Free alphabetic string monoid on A-Z of block length 3 sage: M = E.key_space() sage: A = M([[1,0,1],[0,1,1],[2,2,3]]) sage: A [1 0 1] [0 1 1] [2 2 3] sage: e = E(A) sage: e [1 0 1] [0 1 1] [2 2 3] sage: e(S("LAMAISONBLANCHE")) JYVKSKQPELAYKPV
TESTS:
sage: S = AlphabeticStrings() sage: E = HillCryptosystem(S,3) sage: E == loads(dumps(E)) True
Functions: inverse
Special Functions: __call__,
__eq__,
__init__
Class: SubstitutionCipher
self, parent, key) |
Create a substitution cipher.
Input: parent and key
sage: S = AlphabeticStrings() sage: E = SubstitutionCryptosystem(S) sage: E Substitution cryptosystem on Free alphabetic string monoid on A-Z sage: K = S([ 25-i for i in range(26) ]) sage: K ZYXWVUTSRQPONMLKJIHGFEDCBA sage: e = E(K) sage: m = S("THECATINTHEHAT") sage: e(m) GSVXZGRMGSVSZG
TESTS:
sage: S = AlphabeticStrings() sage: E = SubstitutionCryptosystem(S) sage: E == loads(dumps(E)) True
Functions: inverse
Special Functions: __call__,
__eq__,
__init__
Class: TranspositionCipher
self, parent, key) |
Create a transposition cipher.
Input: parent and key
sage: S = AlphabeticStrings() sage: E = TranspositionCryptosystem(S,14) sage: E Transposition cryptosystem on Free alphabetic string monoid on A-Z of block length 14 sage: K = [ 14-i for i in range(14) ] sage: K [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] sage: e = E(K) sage: m = S("THECATINTHEHAT") sage: e(m) TAHEHTNITACEHT
sage: S = AlphabeticStrings() sage: E = TranspositionCryptosystem(S,15); sage: m = S("THECATANDTHEHAT") sage: G = E.key_space() sage: G Symmetric group of order 15! as a permutation group sage: g = G([ 3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13 ]) sage: e = E(g) sage: e(m) EHTTACDNAEHTTAH
TESTS:
sage: S = AlphabeticStrings() sage: E = TranspositionCryptosystem(S,14) sage: E == loads(dumps(E)) True
Functions: inverse
Special Functions: __call__,
__init__
Class: VigenereCipher
self, parent, key) |
Create a Vigenere cipher.
Input: parent and key
sage: S = AlphabeticStrings() sage: E = VigenereCryptosystem(S,11) sage: K = S("SHAKESPEARE") sage: e = E(K) sage: m = S("THECATINTHEHAT") sage: e(m) LOEMELXRTYIZHT
TESTS:
sage: S = AlphabeticStrings() sage: E = VigenereCryptosystem(S,11) sage: E == loads(dumps(E)) True
Functions: inverse
Special Functions: __call__,
__init__
See About this document... for information on suggesting changes.