Classical Ciphers.

class sage.crypto.classical_cipher.HillCipher(parent, key)

Hill cipher class

__call__(M)
__eq__(right)
__init__(parent, key)

Create a Hill cipher.

INPUT: Parent and key

EXAMPLES:

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
inverse()
class sage.crypto.classical_cipher.SubstitutionCipher(parent, key)

Substitution cipher class

__call__(M)
__eq__(right)
__init__(parent, key)

Create a substitution cipher.

INPUT: Parent and key

EXAMPLES:

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
inverse()
class sage.crypto.classical_cipher.TranspositionCipher(parent, key)

Transition cipher class

__call__(M, mode='ECB')
__init__(parent, key)

Create a transposition cipher.

INPUT: Parent and key

EXAMPLES:

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

EXAMPLES:

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
inverse()
class sage.crypto.classical_cipher.VigenereCipher(parent, key)

Vigenere cipher class

__call__(M, mode='ECB')
__init__(parent, key)

Create a Vigenere cipher.

INPUT: Parent and key

EXAMPLES:

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
inverse()

Previous topic

Classical Cryptosystems

Next topic

Mini-AES

This Page