strgraph := proc(mess, sl, freq, info) local i, j, k, str1, ct, str2, strset, olist, dlist, pos, gcddlist, flist: strset := {}: flist := []: for i from 1 to length(mess)-sl+1 do ct := 1: olist := [i]: dlist := []: pos := i: gcddlist := 0; str1 := substring(mess, i..i+sl-1): if not member(str1, strset) then for j from i+sl to length(mess)-sl+1 do str2 := substring(mess, j..j+sl-1): if str1=str2 then olist := [op(olist), j]; dlist := [op(dlist), j-pos]; pos := j: ct := ct + 1: fi: od: if ct > 1 then gcddlist := igcd(seq(dlist[k], k = 1..nops(dlist))); fi: fi: if ct >= freq and not member(str1, strset) then if info = true then flist := [op(flist), [cat(convert(sl, string)," graph ", str1 ," occurs ", convert(ct, string) ," times at positions ",convert(olist, string), " at distances ",convert(dlist, string),". " , "Prime dlist = ",convert(map(ifactor, dlist), string), ". ", "Gcd of distances = ", convert(gcddlist,string)), ct]]; else flist := [op(flist), [cat(convert(sl, string), " graph ",str1, " occurs ", convert(ct, string)," times"), ct]]; fi: fi: strset := strset union {str1}: od: flist := sort(flist, (x,y) -> evalb(x[2] > y[2])); seq(lprint(flist[i][1]), i = 1..nops(flist)); end: The procedure strgraph is designed to do frequency analysis on messages. It has the form strgraph(mess, sl, info). These parameters allow this procedure to perform multiple task. The parameter mess is the message for which the frequency analysis is to be performed. The parameter sl specifies the length of text string for the frequency analysis. For example, if we are looking for single letter frequencies, sl = 1, if we are looking for digraph frequencies, sl = 2, for trigraphs, sl = 3, etc.. The parameter freq is designed to give a lower bound on the frequency count the routine looks for. For example, if freq = 2, then strgraph will only print results of text strings that occur in the message two or more times (single occurences will not be printed). If freq = 3, then on results of text strings that occur in the message three or more times will be printed, ignoring text strings that occur only once or twice in the text. The info parameter is a boolean (either true or false) parameter designed to give more detailed information about text strings that occur if desired. If info = true, not only will the number of times but more detailed information about the position of where a certain text string occurs in the message and other facts will be given (this will be explained later). If info = false, this information is left out (which is what we will do here).