
Sage 9.4 Reference Manual: Cryptography Release 9.4 The Sage Development Team Aug 24, 2021 CONTENTS 1 Cryptosystems 1 2 Ciphers 5 3 Classical Cryptosystems 7 4 Classical Ciphers 43 5 Simplified DES 45 6 Mini-AES 55 7 DES 75 8 PRESENT 83 9 Blum-Goldwasser Probabilistic Encryption 93 10 Stream Cryptosystems 101 11 Stream Ciphers 105 12 Linear feedback shift register (LFSR) sequence commands 109 13 Utility Functions for Cryptography 113 14 Boolean functions 121 15 S-Boxes and Their Algebraic Representations 133 16 S-Boxes used in cryptographic schemes 151 17 Abstract base class for generators of polynomial systems 159 18 Small Scale Variants of the AES (SR) Polynomial System Generator 163 19 Rijndael-GF 193 20 Hard Lattice Generator 213 21 (Ring-)LWE oracle generators 217 22 Indices and Tables 227 i Python Module Index 229 Index 231 ii CHAPTER ONE CRYPTOSYSTEMS This module contains base classes for various cryptosystems, including symmetric key and public-key cryptosystems. The classes defined in this module should not be called directly. It is the responsibility of child classes toimplement specific cryptosystems. Take for example the Hill or matrix cryptosystem as implemented in HillCryptosystem. It is a symmetric key cipher so HillCryptosystem is a child class of SymmetricKeyCryptosystem, which in turn is a child class of Cryptosystem. The following diagram shows the inheritance relationship of particular cryptosystems: Cryptosystem + SymmetricKeyCryptosystem | + HillCryptosystem | + LFSRCryptosystem | + ShiftCryptosystem | + ShrinkingGeneratorCryptosystem | + SubstitutionCryptosystem | + TranspositionCryptosystem | + VigenereCryptosystem + PublicKeyCryptosystem class sage.crypto.cryptosystem.Cryptosystem(plaintext_space, ciphertext_space, key_space, block_length=1, period=None) Bases: sage.structure.parent_old.Parent, sage.structure.parent.Set_generic A base cryptosystem class. This is meant to be extended by other specialized child classes that implement specific cryptosystems. A cryptosystem is a pair of maps E : K! Hom(M; C) D : K! Hom(C; M) where K is the key space, M is the plaintext or message space, and C is the ciphertext space. In many instances M = C and the images will lie in Aut(M). An element of the image of E is called a cipher. We may assume that E and D are injective, hence identify a key K in K with its image EK := E(K) in Hom(M; C). The cryptosystem has the property that for every encryption key K1 there is a decryption key K2 such that DK2 ∘ EK1 . A cryptosystem with the property that K := K2 = K1, is called a symmetric cryptosystem. Otherwise, if the key K2 6= K1, nor is K2 easily derived from K1, we call the cryptosystem asymmetric or public key. In that case, K1 is called the public key and K2 is called the private key. INPUT: • plaintext_space – the plaintext alphabet. • ciphertext_space – the ciphertext alphabet. 1 Sage 9.4 Reference Manual: Cryptography, Release 9.4 • key_space – the key alphabet. • block_length – (default: 1) the block length. • period – (default: None) the period. EXAMPLES: Various classical cryptosystems: sage: ShiftCryptosystem(AlphabeticStrings()) Shift cryptosystem on Free alphabetic string monoid on A-Z sage: SubstitutionCryptosystem(HexadecimalStrings()) Substitution cryptosystem on Free hexadecimal string monoid sage: HillCryptosystem(BinaryStrings(),3) Hill cryptosystem on Free binary string monoid of block length 3 sage: TranspositionCryptosystem(OctalStrings(),5) Transposition cryptosystem on Free octal string monoid of block length 5 sage: VigenereCryptosystem(Radix64Strings(),7) Vigenere cryptosystem on Free radix 64 string monoid of period 7 block_length() Return the block length of this cryptosystem. For some cryptosystems this is not relevant, in which case the block length defaults to 1. EXAMPLES: The block lengths of various classical cryptosystems: sage: ShiftCryptosystem(AlphabeticStrings()).block_length() 1 sage: SubstitutionCryptosystem(HexadecimalStrings()).block_length() 1 sage: HillCryptosystem(BinaryStrings(),3).block_length() 3 sage: TranspositionCryptosystem(OctalStrings(),5).block_length() 5 sage: VigenereCryptosystem(Radix64Strings(),7).block_length() 1 cipher_codomain() Return the alphabet used by this cryptosystem for encoding ciphertexts. This is the same as the ciphertext space. EXAMPLES: The cipher codomains, or ciphertext spaces, of various classical cryptosystems: sage: ShiftCryptosystem(AlphabeticStrings()).cipher_codomain() Free alphabetic string monoid on A-Z sage: SubstitutionCryptosystem(HexadecimalStrings()).cipher_codomain() Free hexadecimal string monoid sage: HillCryptosystem(BinaryStrings(),3).cipher_codomain() Free binary string monoid sage: TranspositionCryptosystem(OctalStrings(),5).cipher_codomain() Free octal string monoid sage: VigenereCryptosystem(Radix64Strings(),7).cipher_codomain() Free radix 64 string monoid 2 Chapter 1. Cryptosystems Sage 9.4 Reference Manual: Cryptography, Release 9.4 cipher_domain() Return the alphabet used by this cryptosystem for encoding plaintexts. This is the same as the plaintext space. EXAMPLES: The cipher domains, or plaintext spaces, of various classical cryptosystems: sage: ShiftCryptosystem(AlphabeticStrings()).cipher_domain() Free alphabetic string monoid on A-Z sage: SubstitutionCryptosystem(HexadecimalStrings()).cipher_domain() Free hexadecimal string monoid sage: HillCryptosystem(BinaryStrings(),3).cipher_domain() Free binary string monoid sage: TranspositionCryptosystem(OctalStrings(),5).cipher_domain() Free octal string monoid sage: VigenereCryptosystem(Radix64Strings(),7).cipher_domain() Free radix 64 string monoid ciphertext_space() Return the ciphertext alphabet of this cryptosystem. EXAMPLES: The ciphertext spaces of various classical cryptosystems: sage: ShiftCryptosystem(AlphabeticStrings()).ciphertext_space() Free alphabetic string monoid on A-Z sage: SubstitutionCryptosystem(HexadecimalStrings()).ciphertext_space() Free hexadecimal string monoid sage: HillCryptosystem(BinaryStrings(),3).ciphertext_space() Free binary string monoid sage: TranspositionCryptosystem(OctalStrings(),5).ciphertext_space() Free octal string monoid sage: VigenereCryptosystem(Radix64Strings(),7).ciphertext_space() Free radix 64 string monoid key_space() Return the alphabet used by this cryptosystem for encoding keys. EXAMPLES: The key spaces of various classical cryptosystems: sage: ShiftCryptosystem(AlphabeticStrings()).key_space() Ring of integers modulo 26 sage: SubstitutionCryptosystem(HexadecimalStrings()).key_space() Free hexadecimal string monoid sage: HillCryptosystem(BinaryStrings(),3).key_space() Full MatrixSpace of 3 by 3 dense matrices over Ring of integers modulo 2 sage: TranspositionCryptosystem(OctalStrings(),5).key_space() Symmetric group of order 5! as a permutation group sage: VigenereCryptosystem(Radix64Strings(),7).key_space() Free radix 64 string monoid period() 3 Sage 9.4 Reference Manual: Cryptography, Release 9.4 plaintext_space() Return the plaintext alphabet of this cryptosystem. EXAMPLES: The plaintext spaces of various classical cryptosystems: sage: ShiftCryptosystem(AlphabeticStrings()).plaintext_space() Free alphabetic string monoid on A-Z sage: SubstitutionCryptosystem(HexadecimalStrings()).plaintext_space() Free hexadecimal string monoid sage: HillCryptosystem(BinaryStrings(),3).plaintext_space() Free binary string monoid sage: TranspositionCryptosystem(OctalStrings(),5).plaintext_space() Free octal string monoid sage: VigenereCryptosystem(Radix64Strings(),7).plaintext_space() Free radix 64 string monoid class sage.crypto.cryptosystem.PublicKeyCryptosystem(plaintext_space, ciphertext_space, key_space, block_length=1, period=None) Bases: sage.crypto.cryptosystem.Cryptosystem The base class for asymmetric or public-key cryptosystems. class sage.crypto.cryptosystem.SymmetricKeyCryptosystem(plaintext_space, ciphertext_space, key_space, block_length=1, period=None) Bases: sage.crypto.cryptosystem.Cryptosystem The base class for symmetric key, or secret key, cryptosystems. alphabet_size() Return the number of elements in the alphabet of this cryptosystem. This only applies to any cryptosystem whose plaintext and ciphertext spaces are the same alphabet. EXAMPLES: sage: ShiftCryptosystem(AlphabeticStrings()).alphabet_size() 26 sage: ShiftCryptosystem(BinaryStrings()).alphabet_size() 2 sage: ShiftCryptosystem(HexadecimalStrings()).alphabet_size() 16 sage: SubstitutionCryptosystem(OctalStrings()).alphabet_size() 8 sage: SubstitutionCryptosystem(Radix64Strings()).alphabet_size() 64 4 Chapter 1. Cryptosystems CHAPTER TWO CIPHERS class sage.crypto.cipher.Cipher(parent, key) Bases: sage.structure.element.Element Cipher class codomain() domain() key() class sage.crypto.cipher.PublicKeyCipher(parent, key, public=True) Bases: sage.crypto.cipher.Cipher Public key cipher class class sage.crypto.cipher.SymmetricKeyCipher(parent, key) Bases: sage.crypto.cipher.Cipher Symmetric key cipher class 5 Sage 9.4 Reference Manual: Cryptography, Release 9.4 6 Chapter 2. Ciphers CHAPTER THREE CLASSICAL CRYPTOSYSTEMS A convenient user interface to various classical ciphers. These include: • affine cipher; see AffineCryptosystem • Hill or matrix cipher; see HillCryptosystem • shift cipher; see ShiftCryptosystem • substitution cipher; see SubstitutionCryptosystem • transposition cipher; see TranspositionCryptosystem • Vigenere cipher; see VigenereCryptosystem These classical cryptosystems support alphabets such as: • the capital letters of the English alphabet; see AlphabeticStrings() • the hexadecimal
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages242 Page
-
File Size-