Here is another implementation of a cipher using proc fcmp. I have it requiring two generated formats right now as well, but would like to change it to not require them later. I also would want to add the ability to encrypt strings that contain multiple words, right now it will not work properly with spaces in the string. One thing to note that this function uses is the nice feature of proc fcmp, the dynamic_array. Too bad it only works for number arrays and not character also. data v1; alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; retain fmtname '$vigenere'; do label=0 to length(alphabet)-1; start=substr(alphabet,label+1,1); output; end; drop alphabet; run; data v2; alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; retain fmtname 'vigenere'; do start=0 to length(alphabet)-1; label=substr(alphabet,start+1,1); output; end; drop alphabet; run; data _null_; do i=1 to 2; call execute('proc format library=work cntlin=v'|| strip(i) || '; run;'); end; run; proc fcmp outlib=work.func.cipher; function vigenere(string $, mode $, okey $) $32000; length key want $32000; /* construct key */ key=okey; do until(length(key) ge length(string)); key=cats(of key key); end; array k[1] /nosymbols; dims=length(string); call dynamic_array(k,dims); do i=1to dims; k=put(substr(key,i,1),$vigenere.)*1; end; /* split input string*/ array s[1] /nosymbols; array c[1] /nosymbols; call dynamic_array(s,dims); call dynamic_array(c,dims); do ii=1to dims; s[ii]=put(substr(string,ii,1),$vigenere.)*1; /* calculate encipheredletters */ if upcase(mode) in ('E','ENCRYPT')then c[ii]=mod((k[ii]+s[ii]),26); else if upcase(mode) in ('D','DECRYPT')then c[ii]=ifn(mod((s[ii]-k[ii]),26)<0,mod((s[ii]-k[ii]),26)+26,mod((s[ii]-k[ii]),26)); end; want=''; do j=1 to dims; want=strip(want) || strip(put(c , vigenere.)); end; return(want); endsub; run; %let cmplib=%sysfunc(getoption(cmplib)); options cmplib=(work.func &cmplib); data test; input t $; e1=vigenere(t,'e','FRIEDEGG'); d1=vigenere(e1,'d','FRIEDEGG'); cards; TEST REST BEST ; run; options cmplib=(&cmplib); EDIT: By the way, I forgot to mention, this is the Vigenère cipher: http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
... View more