Schrock Polynomial Cipher

This code allows us to input a text and encode or decode it with a polynomial cipher.  Choose an irreducible polynomial p(x) in Fq[x] =Z/qZ[x] for some prime q > 26 (say q = 29). Choose a random integer r and make public g(x) = (p(x)+1)^r mod q.  Alice takes a random s and computes g(x)^s, and encodes her message M(x) by sending Mu(x) =M(x) g(x)^s. Bob then looks at it modulo p(x) (which he knows)  to recover M(x).

shifter[input_,shift_] := Module[{},
temp = Mod[(ToCharacterCode[input][[1]] - 65) + shift,26]+65;
temp = FromCharacterCode[temp];
Return[temp];
];

addletters[input1_,input2_,addsubtract_] := Module[{},
temp = Mod[(ToCharacterCode[input1][[1]] - 65) + addsubtract(ToCharacterCode[input2][[1]]-65),26]+65;
temp = FromCharacterCode[temp];
Return[temp];
];

addletters["E","G",1]
addletters["I","C",-1]
Mod[ToCharacterCode["A"][[1]]-65,26]
(*bob = "D"
addletters["B",bob]*)

tempdata

Clear[x]
?PolynomialMod
PolynomialMod[3x^2+2x+1,x^2+1]
tempdata = Characters["RTRTRTR"]
tempdata

Factor[x^111 + 12 x^110 + 17 x^109 + x^65 + x^64 + 22 x^61 + 11 x^11+14x +5,Modulus -> 29]
PolynomialMod[11 + 43 x, 27]

Factor[25+17 x+17 (x^2)+14 (x^3)+12 (x^4)+10 (x^5)+23 (x^6)+20 (x^7)+7 (x^8)+4 (x^9)+27 (x^10)+24 (x^11)+8 (x^12)+17 (x^13)+19 (x^14)+4 (x^15)+12 (x^16)+27 (x^17)+23 (x^18)+20 (x^19)+2 (x^20)+13 (x^21)+26 (x^22)+15 (x^23)+13 (x^24)+24 (x^25)+11 (x^26)+21 (x^27)+6 (x^28)+8 (x^29)+27 (x^30)+19 (x^31)+27 (x^32)+27 (x^33)+20 (x^34)+7 (x^35)+7 (x^36)+16 (x^37)+23 (x^38)+14 (x^39)+26 (x^40)+19 (x^41)+13 (x^42)+24 (x^43)+9 (x^44)+26 (x^45)+4 (x^46)+9 (x^47)+5 (x^48)+4 (x^49)+19 (x^50)+27 (x^51)+(x^52)+26 (x^53)+27 (x^54)+16 (x^55)+13 (x^56)+4 (x^57)+27 (x^58)+18 (x^59)+28 (x^60)+13 (x^62)+25 (x^63)+26 (x^64)+11 (x^65)+18 (x^66)+13 (x^67)+10 (x^68)+3 (x^69)+4 (x^70)+13 (x^71)+5 (x^72)+12 (x^73)+15 (x^74)+(x^75)+2 (x^77)+11 (x^78)+24 (x^79)+19 (x^80)+25 (x^81)+4 (x^82)+22 (x^83)+2 (x^84)+28 (x^85)+20 (x^86)+24 (x^87)+20 (x^88)+24 (x^89)+(x^90), Modulus -> 29]

Clear[p]; Clear[q];

(* Last argument: 1 to encode, anything else to decode *)
schrocklettercrypt[data_, r_, s_,codeordecode_] := Module[{},
If[codeordecode == 1, sign = 1, sign = -1];
tempdata = Characters[data];
(*tempcodeword = Characters[codeword];*)
deg = 90;
q = 29;
p[x_] := 25+17 x+17 (x^2)+14 (x^3)+12 (x^4)+10 (x^5)+23 (x^6)+20 (x^7)+7 (x^8)+4 (x^9)+27 (x^10)+24 (x^11)+8 (x^12)+17 (x^13)+19 (x^14)+4 (x^15)+12 (x^16)+27 (x^17)+23 (x^18)+20 (x^19)+2 (x^20)+13 (x^21)+26 (x^22)+15 (x^23)+13 (x^24)+24 (x^25)+11 (x^26)+21 (x^27)+6 (x^28)+8 (x^29)+27 (x^30)+19 (x^31)+27 (x^32)+27 (x^33)+20 (x^34)+7 (x^35)+7 (x^36)+16 (x^37)+23 (x^38)+14 (x^39)+26 (x^40)+19 (x^41)+13 (x^42)+24 (x^43)+9 (x^44)+26 (x^45)+4 (x^46)+9 (x^47)+5 (x^48)+4 (x^49)+19 (x^50)+27 (x^51)+(x^52)+26 (x^53)+27 (x^54)+16 (x^55)+13 (x^56)+4 (x^57)+27 (x^58)+18 (x^59)+28 (x^60)+13 (x^62)+25 (x^63)+26 (x^64)+11 (x^65)+18 (x^66)+13 (x^67)+10 (x^68)+3 (x^69)+4 (x^70)+13 (x^71)+5 (x^72)+12 (x^73)+15 (x^74)+(x^75)+2 (x^77)+11 (x^78)+24 (x^79)+19 (x^80)+25 (x^81)+4 (x^82)+22 (x^83)+2 (x^84)+28 (x^85)+20 (x^86)+24 (x^87)+20 (x^88)+24 (x^89)+(x^90);

g[x_] := PolynomialMod[ (p[x]+1)^r, 29];
Print["Public polynomial is g[x] = "];
Print[ g[x]];
Print[" "];

messagepoly = {};
datalength = Length[tempdata];
For[n = 1, n ≤ deg+1, n++,
{
If[n ≤ datalength, messagepoly = AppendTo[messagepoly,ToCharacterCode[tempdata[[n]]][[1]]-65], messagepoly = AppendTo[messagepoly,0]];
}];

M[x_] := Sum[messagepoly[[n]] x^(n-1), {n,1,91}];

Mu[x_] := PolynomialMod[M[x] g[x]^s, 29];

Print["Message is ", Mu[x]];

decryptMu1[x_] := PolynomialReduce[M[x]g[x]^s, p[x],x, Modulus -> 29];
decryptMu2[x_] := decryptMu1[x][[2]];
Print[" "];
Print[decryptMu2[x]];

decrypted = {};
For[n = 0, n ≤ datalength-1, n++, decrypted = AppendTo[decrypted, FromCharacterCode[65+Coefficient[decryptMu2[x],x,n]]]];
Print[StringJoin[decrypted]];

];

schrocklettercrypt["HELLO",5,7,1]

schrocklettercrypt["HISTORYWILLBEKINDTOMEFORIINTENDTOWRITEIT",5,7,1]