#OLD CODE WE NEED: SCROLL DOWN FOR MY WORK #HD(u,v): The Hamming distance between two words (of the same length) HD:=proc(u,v) local i,co: co:=0: for i from 1 to nops(u) do if u[i]<>v[i] then co:=co+1: fi: od: co: end: #RV(q,n): A random word of length n in {0,1,..,q-1} RV:=proc(q,n) local ra,i: ra:=rand(0..q-1): [seq( ra(), i=1..n)]: end: # returns matrix M in standard form SFde:=proc(q,M) local k,n,i,j,S,rj,cj,ri: k:=nops(M); n:=nops(M[1]); S:=copy(M); for i from 1 to k do: # algorithm is iterated from 1 to k # if S_ii = 0, then we need to perform a swap: if S[i,i] = 0 then for j from i+1 to k while S[j,i] = 0 do od; # look for available row if j<=k then # swap rows rj:=GetRow(S,j); S:=SetRow(S,j, GetRow(S,i)); S:=SetRow(S,i,rj); else # look to swap columns for j from i+1 to n while S[i,j] = 0 do od; # look for available col # swap cols cj:=GetCol(S,j); S:=SetCol(S,j, GetCol(S,i)); S:=SetCol(S,i,cj); fi; fi; # scale row to have leading entry 1 ri:=GetRow(S,i); ri:=(ri*(ri[i]&^(-1) mod q)) mod q; S:=SetRow(S,i,ri); for j from 1 to k do: if j <> i then rj:=GetRow(S,j); rj:=(rj - (rj[i] * ri mod q)) mod q; S:=SetRow(S,j,rj); fi: od: od: return S: end: #PCM(q,M): inputs the mod. q and a non-empty basis (a list of lists) #n=nops(M[1]) M is k by n matrix and H=PCM(q,M) is an n-k by n matrix #describing the basis of some linear code over GF(q)^n outputs of dimension k=nops(M) #the (n-k) by n PCM:=proc(q,M) local k,n,i,j,H: option remember: k:=nops(M): n:=nops(M[1]): if [seq([op(1..k,M[i])],i=1..k)]<>[seq([0$(i-1),1,0$(k-i)],i=1..k)] then print(`Not standard form , please use SFde(q,M) first `): RETURN(FAIL): fi: for i from 1 to n-k do for j from 1 to k do H[i,j]:=-M[j][i+k] mod q: od: for j from k+1 to n do if j-k=i then H[i,j]:=1: else H[i,j]:=0: fi: od: od: [seq([seq(H[i,j],j=1..n)],i=1..n-k)]: end: LtoC:=proc(q,M) local n,k,C,c,i,M1: option remember: k:=nops(M): n:=nops(M[1]): if k=1 then RETURN({seq(i*M[1] mod q,i=0..q-1) }): fi: M1:=M[1..k-1]: C:=LtoC(q,M1): {seq(seq(c+i*M[k] mod q,i=0..q-1),c in C)}: end: #MinW(q,M): The minimal weight of the Linear code generated by M over GF(q) MinW:=proc(q,M) local n,C,c: n:=nops(M[1]): C:=LtoC(q,M): min( seq(HD(c,[0$n]), c in C minus {[0$n]} )): end: #CC(P,k1): Implements the Ceaser Code #Inputs a message, given a list of characters, P (in lower case) #and an integer k from 0 to 25, outputs the encrypted message #For example #CC([d,o,r,o,n],2); should output [f,q,t,q,p] CC:=proc(P,k1) local A,T,i1: A:=[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]: for i1 from 1 to nops(A) do T[A[i1]]:=A[(i1+k1-1 mod 26)+1]: od: [seq(T[P[i1]],i1=1..nops(P))]: end: #DP(q,u,v): DP:=proc(q,u,v) local i,n: n:=nops(u): add(u[i]*v[i],i=1..n) mod q: end: #Syn(q,H,y): The syndrom of the transmitted vector y if the PCM is H #(a row vector of length n-k) Syn:=proc(q,H,y) local i: [seq(DP(q,y,H[i]),i=1..nops(H))]: end: #SynT(q,M): inputs q and a basis (in standard form) M of some linear code over GF(q) #outputs the syndrom table mapping each possible syndorm to its correponding #coset leader in its standard array. SynT:=proc(q,M) local n,T,A,H,S,s,i: option remember: #S is the set of syndroms and T is the synrome table if SFde(q,M)<>M then RETURN(FAIL): fi: n:=nops(M[1]): A:=SAah(q,n,M): H:=PCM(q,M): S:={}: for i from 1 to nops(A) do s:=Syn(q,H,A[i][1]): S:=S union {s}: T[s]:=A[i][1]: od: op(T),S: end: RV:=proc(q,n) local ra,i: ra:=rand(0..q-1): [seq( ra(), i=1..n)]: end: Fqn:=proc(q,n) local S,a,v: option remember: if n=0 then RETURN({[]}): fi: #BEGINNING OF MY WORK___________________________________________ #______________________________________________________________ #1. Age Check AV := [b,e,h,o,x,v,h,w,b,g,z,m,a,x,h,k,r]: # & RaB, SB AH := [f,i,l,s,b,z,l,a,f,k,d,q,e,b,l,o,v]: GL := [d,g,j,q,z,x,j,y,d,i,b,o,c,z,j,m,t]: HC := [e,w,h,k,r,a,w,z,k,e,j,c,w,p,d,a,k,n,u]: JK := [c,f,i,p,y,w,i,x,c,h,a,n,b,y,i,l,s]: # & RyB KW := [e,h,k,r,a,y,k,z,e,j,c,p,d,a,k,n,u]: LM := [h,k,n,u,d,b,n,c,h,m,f,s,g,d,n,q,x]: NTS := [g,j,m,t,o,a,m,b,g,l,e,r,f,c,m,p,w]: PB := [d,v,g,j,q,v,y,j,z,d,i,b,v,o,c,j,m,t]: #^thanks to Aurora for typing out these lists AgeCheck:=proc(n) local shift, A, ind,K: A:=[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]: with(ListTools): #Search lets me find the index of the first letter of the encrypted #message n[1], which I know was originally i, in the alphabet A. ind:=Search(n[1], A)-Search(i, A) mod 26: print(ind); #if n<>CC(n, ind) then print("incorrect encrypted message") end if; print(CC(n,-ind mod 26)): #print("the age corresponding to n is ", ind): end: #2. antiPCM: #want to invert the operation of taking the parity check matrix of M #this assignment doesn't say anything about using/not using linalg, so #we will use it here. antiPCM:=proc(q,H) local NegATrans,n, M, K: #Use Theorem 7.6 in Folland with(linalg): n:=nops(H[1]): NegATrans:=-transpose(H[1..n-q, 1..n-q]): K:=IdentityMatrix(q): M:=transpose(Matrix([transpose(K), transpose(NegATrans)])): return(M); end: #3. DecodeLT(q,M): DecodeLT:=proc(q,M) local n, v, s, H, S, leader, Decoded: #obtaining a vector in F(q,n) n:=nops(M[1]): H:=PCM(q,M): #finding the syndrome table S:=SynT(q,M)[1]: for v in Fqn(q,n) do: #finding the syndrome of the vector s:=Syn(q, H, v): #finding the position of the corresponding syndrome [r,c]=find(S=s): #finding the coset leader leader:=S[r,1]: Decoded:=v-leader; od: end: