Size: 4447
Comment:
|
← Revision 6 as of 2008-11-14 13:41:58 ⇥
Size: 4447
Comment: converted to 1.6 markup
|
No differences found! |
Cryptography
Linear feedback shift registers (LFSRs)
A special type of stream cipher is implemented in Sage, namely, a LFSR sequence defined over a finite field. Stream ciphers have been used for a long time as a source of pseudo-random number generators.
S. Golomb ("Shift register sequences", Aegean Park Press, Laguna Hills, Ca, 1967) gives a list of three statistical properties a sequence of numbers
In the case where
Assume
balance:
|∑Pn=1(−1)an|≤1 .low autocorrelation:
C(k)={1,k=0,ϵ,k≠0. (For sequences satisfying these first two properties, it is known that
ε=−1/P must hold.)
proportional runs property: In each period, half the runs have length
1 , one-fourth have length2 , etc. Moreover, there are as many runs of1 's as there are of 0 's.
A sequence satisfying these properties will be called pseudo-random.
A general feedback shift register is a map
where
for some given constants
is sometimes called the connection polynomial.
Example: Over
The LFSR sequence is then
The sequence of
sage: F = GF(2) sage: o = F(0) sage: l = F(1) sage: key = [l,o,o,l]; fill = [l,l,o,l]; n = 20 sage: s = lfsr_sequence(key,fill,n); s [1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0] sage: lfsr_autocorrelation(s,15,7) 4/15 sage: lfsr_autocorrelation(s,15,0) 8/15 sage: lfsr_connection_polynomial(s) x^4 + x + 1 sage: berlekamp_massey(s) x^4 + x^3 + 1
Classical crytosystems
Sage has a type for cryptosystems (created by David Kohel, who also wrote the examples below), implementing classical cryptosystems. The general interface is as follows:
sage: S = AlphabeticStrings() sage: S Free alphabetic string monoid on A-Z 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: e = E(K) sage: m = S("THECATINTHEHAT") sage: e(m) GSVXZGRMGSVSZG
Here's another example:
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
The idea is that a cryptosystem is a map