A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
S = AlphabeticStrings()
E = SubstitutionCryptosystem(S)
X = pt.frequency_distribution()
Z = ct.frequency_distribution()
Y = DiscreteRandomVariable(X,Z.function())
for j in range(26):
... K = S([ (j+k)%26 for k in range(26) ])
... print "%s: %s" % (j, X.translation_correlation(Y,E(K)))
X = pt.frequency_distribution()
m = 11
r = 0.75
match = [ [] for i in range(m) ]
for i in range(m):
... Z = ct[i::m].frequency_distribution()
... Y = DiscreteRandomVariable(X,Z.function())
... for j in range(26):
... K = S([ (j+k)%26 for i in range(26) ])
... corr = X.translation_correlation(Y,E(K))
... if corr > r:
... match[i].append(j)
Exercise
F2 = FiniteField(2)
PS.<x> = PowerSeriesRing(F2)
f = x^2 + x
g = x^3 + x + 1
f/g + O(x^16)
x + x^4 + x^5 + x^6 + x^8 + x^11 + x^12 + x^13 + x^15 + O(x^16)