Skip to content

Commit 9d5554c

Browse files
author
Matthias Koeppe
committed
sage.crypto: Update # needs, use more block tags, doctest cosmetics
1 parent 6d39144 commit 9d5554c

File tree

11 files changed

+226
-204
lines changed

11 files changed

+226
-204
lines changed

src/sage/crypto/block_cipher/miniaes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sage.doctest: needs sage.modules sage.rings.finite_rings
1+
# sage.doctest: needs sage.combinat sage.modules sage.rings.finite_rings
22
r"""
33
Mini-AES
44

src/sage/crypto/boolean_function.pyx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ EXAMPLES::
1717
Boolean function with 8 variables
1818
sage: B.nonlinearity()
1919
112
20-
sage: B.algebraic_immunity()
20+
sage: B.algebraic_immunity() # needs sage.rings.polynomial.pbori
2121
4
2222
2323
AUTHOR:
@@ -62,7 +62,7 @@ cdef walsh_hadamard(long *f, int ldn):
6262
6363
sage: from sage.crypto.boolean_function import BooleanFunction
6464
sage: B = BooleanFunction([1,0,0,1])
65-
sage: B.walsh_hadamard_transform() # indirect doctest
65+
sage: B.walsh_hadamard_transform() # indirect doctest
6666
(0, 0, 0, -4)
6767
"""
6868
cdef long n, ldm, m, mh, t1, t2, r, j, u, v
@@ -566,23 +566,24 @@ cdef class BooleanFunction(SageObject):
566566
sage: BooleanFunction('00ab').truth_table(format='hex') # needs sage.rings.polynomial.pbori
567567
'00ab'
568568
569+
sage: # needs sage.rings.polynomial.pbori
569570
sage: H = '0abbacadabbacad0'
570571
sage: len(H)
571572
16
572-
sage: T = BooleanFunction(H).truth_table(format='hex') # needs sage.rings.polynomial.pbori
573+
sage: T = BooleanFunction(H).truth_table(format='hex')
573574
sage: T == H
574575
True
575576
sage: H = H * 4
576-
sage: T = BooleanFunction(H).truth_table(format='hex') # needs sage.rings.polynomial.pbori
577+
sage: T = BooleanFunction(H).truth_table(format='hex')
577578
sage: T == H
578579
True
579580
sage: H = H * 4
580-
sage: T = BooleanFunction(H).truth_table(format='hex') # needs sage.rings.polynomial.pbori
581+
sage: T = BooleanFunction(H).truth_table(format='hex')
581582
sage: T == H
582583
True
583584
sage: len(T)
584585
256
585-
sage: B.truth_table(format='oct') # needs sage.rings.polynomial.pbori
586+
sage: B.truth_table(format='oct')
586587
Traceback (most recent call last):
587588
...
588589
ValueError: unknown output format
@@ -1073,9 +1074,10 @@ cdef class BooleanFunction(SageObject):
10731074
sage: B.algebraic_immunity()
10741075
2
10751076
1076-
sage: R.<x> = GF(2^8,'a')[] # needs sage.rings.finite_rings
1077-
sage: B = BooleanFunction(x^31) # needs sage.rings.finite_rings sage.rings.polynomial.pbori
1078-
sage: B.algebraic_immunity() # needs sage.rings.finite_rings
1077+
sage: # needs sage.rings.finite_rings sage.rings.polynomial.pbori
1078+
sage: R.<x> = GF(2^8,'a')[]
1079+
sage: B = BooleanFunction(x^31)
1080+
sage: B.algebraic_immunity()
10791081
4
10801082
"""
10811083
f = self
@@ -1101,13 +1103,14 @@ cdef class BooleanFunction(SageObject):
11011103
11021104
EXAMPLES::
11031105
1106+
sage: # needs sage.rings.polynomial.pbori
11041107
sage: from sage.crypto.boolean_function import BooleanFunction
1105-
sage: B.<x0, x1, x2, x3> = BooleanPolynomialRing() # needs sage.rings.polynomial.pbori
1106-
sage: f = BooleanFunction(x1*x2 + x1*x2*x3 + x1) # needs sage.rings.polynomial.pbori
1107-
sage: f.algebraic_degree() # needs sage.rings.polynomial.pbori
1108+
sage: B.<x0, x1, x2, x3> = BooleanPolynomialRing()
1109+
sage: f = BooleanFunction(x1*x2 + x1*x2*x3 + x1)
1110+
sage: f.algebraic_degree()
11081111
3
11091112
sage: g = BooleanFunction([0, 0])
1110-
sage: g.algebraic_degree() # needs sage.rings.polynomial.pbori
1113+
sage: g.algebraic_degree()
11111114
-1
11121115
"""
11131116
return self.algebraic_normal_form().degree()
@@ -1247,15 +1250,16 @@ cdef class BooleanFunction(SageObject):
12471250
12481251
EXAMPLES::
12491252
1253+
sage: # needs sage.modules
12501254
sage: from sage.crypto.boolean_function import BooleanFunction
12511255
sage: f = BooleanFunction([0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0])
1252-
sage: LS = f.linear_structures() # needs sage.modules
1253-
sage: LS.dimension() # needs sage.modules
1256+
sage: LS = f.linear_structures()
1257+
sage: LS.dimension()
12541258
2
1255-
sage: LS.basis_matrix() # needs sage.modules
1259+
sage: LS.basis_matrix()
12561260
[1 0 0 0]
12571261
[0 0 0 1]
1258-
sage: LS.list() # needs sage.modules
1262+
sage: LS.list()
12591263
[(0, 0, 0, 0), (1, 0, 0, 0), (0, 0, 0, 1), (1, 0, 0, 1)]
12601264
"""
12611265
from sage.modules.free_module import VectorSpace
@@ -1282,15 +1286,16 @@ cdef class BooleanFunction(SageObject):
12821286
12831287
EXAMPLES::
12841288
1289+
sage: # needs sage.rings.polynomial.pbori
12851290
sage: from sage.crypto.boolean_function import BooleanFunction
12861291
sage: f = BooleanFunction([0,1,0,1,0,1,0,1])
1287-
sage: f.derivative(1).algebraic_normal_form() # needs sage.rings.polynomial.pbori
1292+
sage: f.derivative(1).algebraic_normal_form()
12881293
1
12891294
sage: u = [1,0,0]
1290-
sage: f.derivative(u).algebraic_normal_form() # needs sage.rings.polynomial.pbori
1295+
sage: f.derivative(u).algebraic_normal_form()
12911296
1
12921297
sage: v = vector(GF(2), u) # needs sage.modules
1293-
sage: f.derivative(v).algebraic_normal_form() # needs sage.modules sage.rings.finite_rings sage.rings.polynomial.pbori
1298+
sage: f.derivative(v).algebraic_normal_form() # needs sage.modules
12941299
1
12951300
sage: f.derivative(8).algebraic_normal_form()
12961301
Traceback (most recent call last):
@@ -1392,7 +1397,7 @@ def unpickle_BooleanFunction(bool_list):
13921397
13931398
sage: from sage.crypto.boolean_function import BooleanFunction
13941399
sage: B = BooleanFunction([0,1,1,0])
1395-
sage: loads(dumps(B)) == B # indirect doctest
1400+
sage: loads(dumps(B)) == B # indirect doctest
13961401
True
13971402
"""
13981403
return BooleanFunction(bool_list)
@@ -1425,7 +1430,7 @@ cdef class BooleanFunctionIterator:
14251430
14261431
sage: from sage.crypto.boolean_function import BooleanFunction
14271432
sage: B = BooleanFunction(1)
1428-
sage: [b for b in B] # indirect doctest
1433+
sage: [b for b in B] # indirect doctest
14291434
[False, False]
14301435
"""
14311436
return self

src/sage/crypto/classical.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ def inverse_key(self, a, b):
12051205
capital letters of the English alphabet, there are 12 such integers
12061206
relatively prime to `n`::
12071207
1208-
sage: euler_phi(A.alphabet_size())
1208+
sage: euler_phi(A.alphabet_size()) # needs sage.libs.pari
12091209
12
12101210
12111211
And here is a list of those integers::
@@ -3306,8 +3306,7 @@ def __call__(self, K):
33063306
sage: M = AlphabeticStrings()
33073307
sage: E = TranspositionCryptosystem(M,14); E # needs sage.groups
33083308
Transposition cryptosystem on Free alphabetic string monoid on A-Z of block length 14
3309-
sage: K = [ 14-i for i in range(14) ]
3310-
sage: K
3309+
sage: K = [14 - i for i in range(14)]; K
33113310
[14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
33123311
sage: e = E(K) # needs sage.groups
33133312
sage: m = M("THECATINTHEHAT")
@@ -3331,10 +3330,9 @@ def _repr_(self):
33313330
EXAMPLES::
33323331
33333332
sage: A = AlphabeticStrings()
3334-
sage: T = TranspositionCryptosystem(A, 14)
3335-
sage: T
3333+
sage: T = TranspositionCryptosystem(A, 14); T # needs sage.groups
33363334
Transposition cryptosystem on Free alphabetic string monoid on A-Z of block length 14
3337-
sage: T._repr_()
3335+
sage: T._repr_() # needs sage.groups
33383336
'Transposition cryptosystem on Free alphabetic string monoid on A-Z of block length 14'
33393337
"""
33403338
return "Transposition cryptosystem on %s of block length %s" % (

src/sage/crypto/classical_cipher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,15 @@ def __init__(self, parent, key):
477477
sage: K = [ 14-i for i in range(14) ]; K
478478
[14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
479479
sage: e = E(K) # needs sage.groups
480-
sage: m = S("THECATINTHEHAT") # needs sage.groups
480+
sage: m = S("THECATINTHEHAT")
481481
sage: e(m) # needs sage.groups
482482
TAHEHTNITACEHT
483483
484484
EXAMPLES::
485485
486486
sage: S = AlphabeticStrings()
487487
sage: E = TranspositionCryptosystem(S,15) # needs sage.groups
488-
sage: m = S("THECATANDTHEHAT") # needs sage.groups
488+
sage: m = S("THECATANDTHEHAT")
489489
sage: G = E.key_space(); G # needs sage.groups
490490
Symmetric group of order 15! as a permutation group
491491
sage: g = G([ 3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13 ]) # needs sage.groups

src/sage/crypto/cryptosystem.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Cryptosystem(parent_old.Parent, Set_generic):
9797
Substitution cryptosystem on Free hexadecimal string monoid
9898
sage: HillCryptosystem(BinaryStrings(), 3)
9999
Hill cryptosystem on Free binary string monoid of block length 3
100-
sage: TranspositionCryptosystem(OctalStrings(), 5)
100+
sage: TranspositionCryptosystem(OctalStrings(), 5) # needs sage.groups
101101
Transposition cryptosystem on Free octal string monoid of block length 5
102102
sage: VigenereCryptosystem(Radix64Strings(), 7)
103103
Vigenere cryptosystem on Free radix 64 string monoid of period 7
@@ -130,7 +130,7 @@ def __init__(self, plaintext_space, ciphertext_space, key_space,
130130
Substitution cryptosystem on Free hexadecimal string monoid
131131
sage: HillCryptosystem(BinaryStrings(), 3)
132132
Hill cryptosystem on Free binary string monoid of block length 3
133-
sage: TranspositionCryptosystem(OctalStrings(), 5)
133+
sage: TranspositionCryptosystem(OctalStrings(), 5) # needs sage.groups
134134
Transposition cryptosystem on Free octal string monoid of block length 5
135135
sage: VigenereCryptosystem(Radix64Strings(), 7)
136136
Vigenere cryptosystem on Free radix 64 string monoid of period 7
@@ -173,9 +173,9 @@ def __eq__(self, right):
173173
sage: hill2 = HillCryptosystem(AlphabeticStrings(), 4)
174174
sage: hill1 == hill2
175175
True
176-
sage: tran1 = TranspositionCryptosystem(HexadecimalStrings(), 5)
177-
sage: tran2 = TranspositionCryptosystem(HexadecimalStrings(), 5)
178-
sage: tran1 == tran2
176+
sage: tran1 = TranspositionCryptosystem(HexadecimalStrings(), 5) # needs sage.groups
177+
sage: tran2 = TranspositionCryptosystem(HexadecimalStrings(), 5) # needs sage.groups
178+
sage: tran1 == tran2 # needs sage.groups
179179
True
180180
sage: vig1 = VigenereCryptosystem(AlphabeticStrings(), 7)
181181
sage: vig2 = VigenereCryptosystem(AlphabeticStrings(), 7)
@@ -196,9 +196,9 @@ def __eq__(self, right):
196196
sage: hill2 = HillCryptosystem(Radix64Strings(), 5)
197197
sage: hill1 == hill2
198198
False
199-
sage: tran1 = TranspositionCryptosystem(Radix64Strings(), 3)
200-
sage: tran2 = TranspositionCryptosystem(HexadecimalStrings(), 3)
201-
sage: tran1 == tran2
199+
sage: tran1 = TranspositionCryptosystem(Radix64Strings(), 3) # needs sage.groups
200+
sage: tran2 = TranspositionCryptosystem(HexadecimalStrings(), 3) # needs sage.groups
201+
sage: tran1 == tran2 # needs sage.groups
202202
False
203203
sage: vig1 = VigenereCryptosystem(AlphabeticStrings(), 7)
204204
sage: vig2 = VigenereCryptosystem(Radix64Strings(), 7)
@@ -226,7 +226,7 @@ def plaintext_space(self):
226226
Free hexadecimal string monoid
227227
sage: HillCryptosystem(BinaryStrings(), 3).plaintext_space()
228228
Free binary string monoid
229-
sage: TranspositionCryptosystem(OctalStrings(), 5).plaintext_space()
229+
sage: TranspositionCryptosystem(OctalStrings(), 5).plaintext_space() # needs sage.groups
230230
Free octal string monoid
231231
sage: VigenereCryptosystem(Radix64Strings(), 7).plaintext_space()
232232
Free radix 64 string monoid
@@ -249,7 +249,7 @@ def cipher_domain(self):
249249
Free hexadecimal string monoid
250250
sage: HillCryptosystem(BinaryStrings(), 3).cipher_domain()
251251
Free binary string monoid
252-
sage: TranspositionCryptosystem(OctalStrings(), 5).cipher_domain()
252+
sage: TranspositionCryptosystem(OctalStrings(), 5).cipher_domain() # needs sage.groups
253253
Free octal string monoid
254254
sage: VigenereCryptosystem(Radix64Strings(), 7).cipher_domain()
255255
Free radix 64 string monoid
@@ -270,7 +270,7 @@ def ciphertext_space(self):
270270
Free hexadecimal string monoid
271271
sage: HillCryptosystem(BinaryStrings(), 3).ciphertext_space()
272272
Free binary string monoid
273-
sage: TranspositionCryptosystem(OctalStrings(), 5).ciphertext_space()
273+
sage: TranspositionCryptosystem(OctalStrings(), 5).ciphertext_space() # needs sage.groups
274274
Free octal string monoid
275275
sage: VigenereCryptosystem(Radix64Strings(), 7).ciphertext_space()
276276
Free radix 64 string monoid
@@ -293,7 +293,7 @@ def cipher_codomain(self):
293293
Free hexadecimal string monoid
294294
sage: HillCryptosystem(BinaryStrings(), 3).cipher_codomain()
295295
Free binary string monoid
296-
sage: TranspositionCryptosystem(OctalStrings(), 5).cipher_codomain()
296+
sage: TranspositionCryptosystem(OctalStrings(), 5).cipher_codomain() # needs sage.groups
297297
Free octal string monoid
298298
sage: VigenereCryptosystem(Radix64Strings(), 7).cipher_codomain()
299299
Free radix 64 string monoid
@@ -314,7 +314,7 @@ def key_space(self):
314314
Free hexadecimal string monoid
315315
sage: HillCryptosystem(BinaryStrings(), 3).key_space()
316316
Full MatrixSpace of 3 by 3 dense matrices over Ring of integers modulo 2
317-
sage: TranspositionCryptosystem(OctalStrings(), 5).key_space()
317+
sage: TranspositionCryptosystem(OctalStrings(), 5).key_space() # needs sage.groups
318318
Symmetric group of order 5! as a permutation group
319319
sage: VigenereCryptosystem(Radix64Strings(), 7).key_space()
320320
Free radix 64 string monoid
@@ -336,7 +336,7 @@ def block_length(self):
336336
1
337337
sage: HillCryptosystem(BinaryStrings(), 3).block_length()
338338
3
339-
sage: TranspositionCryptosystem(OctalStrings(), 5).block_length()
339+
sage: TranspositionCryptosystem(OctalStrings(), 5).block_length() # needs sage.groups
340340
5
341341
sage: VigenereCryptosystem(Radix64Strings(), 7).block_length()
342342
1

src/sage/crypto/lwe.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sage.doctest: optional - scipy
1+
# sage.doctest: needs scipy sage.symbolic
22
"""
33
(Ring-)LWE oracle generators
44
@@ -52,6 +52,7 @@
5252
5353
Note that Ring-LWE samples are returned as vectors::
5454
55+
sage: # needs sage.libs.pari
5556
sage: from sage.crypto.lwe import RingLWE
5657
sage: from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler
5758
sage: D = DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], euler_phi(16), 5)
@@ -306,7 +307,7 @@ def __init__(self, n, q, D, secret_dist='uniform', m=None):
306307
sage: from sage.crypto.lwe import LWE
307308
sage: lwe = LWE(n=20, q=next_prime(400), D=D, m=30)
308309
sage: _ = [lwe() for _ in range(30)]
309-
sage: lwe() # 31
310+
sage: lwe() # 31
310311
Traceback (most recent call last):
311312
...
312313
IndexError: Number of available samples exhausted.
@@ -539,8 +540,8 @@ def __init__(self, N, q, D, poly=None, secret_dist='uniform', m=None):
539540
540541
sage: from sage.crypto.lwe import RingLWE
541542
sage: from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler
542-
sage: D = DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], n=euler_phi(20), sigma=3.0)
543-
sage: RingLWE(N=20, q=next_prime(800), D=D)
543+
sage: D = DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], n=euler_phi(20), sigma=3.0) # needs sage.libs.pari
544+
sage: RingLWE(N=20, q=next_prime(800), D=D) # needs sage.libs.pari
544545
RingLWE(20, 809, Discrete Gaussian sampler for polynomials of degree < 8 with σ=3.000000 in each component, x^8 - x^6 + x^4 - x^2 + 1, 'uniform', None)
545546
"""
546547
self.N = ZZ(N)
@@ -587,14 +588,15 @@ def __call__(self):
587588
"""
588589
EXAMPLES::
589590
591+
sage: # needs sage.libs.pari
590592
sage: from sage.crypto.lwe import DiscreteGaussianDistributionPolynomialSampler, RingLWE
591593
sage: N = 16
592-
sage: n = euler_phi(N)
593-
sage: D = DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], n, 5)
594-
sage: ringlwe = RingLWE(N, 257, D, secret_dist='uniform')
595-
sage: ringlwe()[0].parent()
594+
sage: n = euler_phi(N) # needs sage.libs.pari
595+
sage: D = DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], n, 5) # needs sage.libs.pari
596+
sage: ringlwe = RingLWE(N, 257, D, secret_dist='uniform') # needs sage.libs.pari
597+
sage: ringlwe()[0].parent() # needs sage.libs.pari
596598
Vector space of dimension 8 over Ring of integers modulo 257
597-
sage: ringlwe()[1].parent()
599+
sage: ringlwe()[1].parent() # needs sage.libs.pari
598600
Vector space of dimension 8 over Ring of integers modulo 257
599601
"""
600602
if self.m is not None:

0 commit comments

Comments
 (0)