University of Sydney_MATH2068_Number Theory and Cryptography_2013 Semester 2
Attach("m2068crypto.m");
"(Magma functions defined for use in MATH2068/2988)";
NewLogFile:=procedure(newname)
SetLogFile(newname);
Write("newlyspecifiedlogfilename.txt",newname: Overwrite:=true);
end procedure;
SetHistorySize(10000);
alphabet:=["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"];
FreqDist:=function(ct)
return [<FrequencyDistribution(ct)[i],alphabet[i]>: i in [1..26]];
end function;
SortedFreqDist:=function(ct)
x,pi:=Sort(FrequencyDistribution(ct),func<x,y|y-x>);
return [FreqDist(ct)[i^pi]: i in [1..26]];
end function;
SortedFreqDist:=function(ct)
fd:=FreqDist(ct);
sfd:=[];
for i := 1 to 26 do
_,M:=Max([fd[j,1]: j in [1..27-i]]);
sfd[i]:=fd[M];
Remove(~fd,M);
end for;
return sfd;
end function;
AlphToInt:=function(x)
return Index(alphabet,x);
end function;
IntToAlph:=function(x)
xx:= x mod 26;
if xx eq 0 then xx:=26;
end if;
return alphabet[xx];
end function;
typical:=[CartesianProduct(RealField(8),Parent("A"))| <0.12583125999,"E">, <0.09216541997,"T">, <0.08250207996,"A">, <0.07751454997,"O">, <0.07148794997,"S">, <0.06972152998,"I">, <0.06764338996,"N">, <0.05787613999,"H">, <0.05569409998,"R">, <0.04426433998,"L">, <0.03574396998,"D">, <0.02753532999,"M">, <0.02722360999,"U">, <0.022859519993,"C">, <0.022547799994,"G">, <0.021924359991,"Y">, <0.021716539992,"F">, <0.021300909994,"W">, <0.019638399989,"P">, <0.014339149993,"B">, <0.010806319996,"V">, <0.005714879997,"K">, <0.0011429799997,"J">, <0.0011429799997,"X">, <0.0009351599996,"Q">, <0.0007273499995,"Z">];
order:=[5, 20, 1, 15, 9, 14, 19, 8, 18, 4, 12, 21, 3, 13, 23, 6, 7, 25, 16, 2, 22, 11, 10, 24, 17, 26];
freqkey:=function(ct)
sfd:=SortedFreqDist(ct);
nums:=[AlphToInt(sfd[i,2]): i in [1..26]];
return &cat[IntToAlph(order[Index(nums,i)]): i in [1..26]];
end function;
swap:=procedure(x,y,~key);
sk:=[AlphToInt(String(key)[i]): i in [1..26]];
G:=Sym(26);
pi:=G!(Index(sk,AlphToInt(x)),Index(sk,AlphToInt(y)));
key:=Parent(key)!&cat[IntToAlph(sk[i^pi]):i in [1..26]];
end procedure;
rotateKey:=procedure(x,y,~key,ct);
sk:=[String(key)[i]: i in [1..26]];
fd:=SortedFreqDist(ct);
inc:=1;
for i:=1 to 26 do
if fd[i,2] eq x then
inc:=-1;
elif fd[i,2] eq y then
l:=i;
break;
end if;
end for;
nsk:=sk;
nsk[Index(sk,y)]:=x;
repeat
l+:=inc;
t:=fd[l,2];
nsk[Index(sk,t)]:=y;
y:=t;
until y eq x;
key:=Parent(key)!&cat nsk;
end procedure;
CheckPeriod:=procedure(text,seq,a,b);
if Type(text) eq CryptTxt then
t:=String(text);
else
t:=text;
end if;
for i in seq do
"Checking for transposition cipher period",i;
for j:=1 to i-1 do
for k:=j+1 to i do
if CoincidenceIndex(Decimation(t,[j,k],i)) gt a then
if CoincidenceDiscriminant(Decimation(t,[j,k],i)) gt b then
i,"is possible";
break j;
end if;
end if;
end for;
end for;
end for;
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_graphtute05_电脑...Find the chromatic number and edge chromatic number of the following graphs:...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_graphtute04_冶金/...**9. Find the number of spanning trees of the complete bipartite graph ...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_prac01_冶金/矿山/地质_工程科技_专业资料。University of Sydney_MATH2069_DiscreteMathematicsAndGraph...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_graphtute03_冶金/...For any positive integers m < n, let T (n, m) denote the number of...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_tute01_电脑基础...fth? (Hint : what positions can the digit 1 occupy in such a number?)...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_tute03s_冶金/矿山...Solution: We need to add to the previous answer the number of hands ...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_tute04_冶金/矿山/...*8. For which n is the Fibonacci number Fn even, and for which n is...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_2008advanceddiscreteexam_冶金/矿山/地质_工程科技_专业资料。University of Sydney_MATH2069_Discrete...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_2007graphexam_冶金/...The number of di?erent Hamiltonian cycles in the complete graph K13 is:...
MATH2069_DiscreteMathematicsAndGraphTheory_2014 Semester 1_2008discreteexam_冶金/矿山/地质_工程科技_专业资料。University of Sydney_MATH2069_DiscreteMathematics...
热门文档