conversaoRSA.mws

Conversão texto - inteiros

(usando a tabela da cifra de César)

30/09/07

 > para_numero := proc(mensagem)

local sl, cn, sn, ii, ntable;

ntable := table(['a'=0, 'b'=1, 'c'=2, 'd'=3, 'e'=4, 'f'=5, 'g'=6, 'h'=7, 'i'=8, 'j'=9, 'l'=10,

'm'=11, 'n'=12, 'o'=13, 'p'=14, 'q'=15, 'r'=16, 's'=17, 't'=18, 'u'=19, 'v'=20, 'x'=21, 'z'=22]):

sl := length(mensagem);

cn := 0;

for ii from 1 to sl do

sn := ntable[substring(mensagem,ii..ii)]:

cn := 100*cn + sn:

od:

RETURN(cn):

end:

 > para_numero(fugirdepressa);

 > para_numero(returntoheadquarters);

 > para_letra := proc(num)

local sl, cs, cn, sn, a, b, c, d, e, f, g, h, i, j, l, m, n, o, p, q, r, s, t, u, v, x, z, ltable, ans;

ltable := table([0=a, 1=b, 2=c, 3=d, 4=e, 5=f, 6=g, 7=h, 8=i, 9=j, 10=l,

11=m, 12=n, 13=o, 14=p, 15=q, 16=r, 17=s, 18=t, 19=u, 20=v, 21=x, 22=z]);

cn := num;

sl := floor(trunc(evalf(log10(cn)))/2) + 1:

ans := ``;

for i from 1 to sl do

cn := cn/100;

cs := ltable[frac(cn)*100];

ans := cat(cs, ans);

cn := trunc(cn);

od:

RETURN(ans):

end:

 > para_letra(5190608160304141604171700);

 > para_letra(1604181916121813070400031519001618041617);

 > para_numero(estudemestruturasdiscretas);

 > para_letra(417181903041104171816191819160017030817021604180017);