signature

My attempt at a signature-size implementation of the Trivium cipher:

from sys import*;c,t=[1]*3+[0]*108,[];l=lambda k:[map(int,list(bin(x)[2:])) for x in k]
k,i=map(lambda x:sum(l(map(ord,x)),t),argv[1:]);a,b,w=[0]*93+k,[0]*88+i,[0,1,2]
def r():t.append(c[-66]^c[-111]^a[-66]^a[-93]^b[-69]^b[-84]);\
na=c[-66]^c[-111]^(c[-110]&c[-109])^a[-69];nb=a[-66]^a[-93]^(a[-92]&a[-91])^b[-78];\
nc=b[-69]^b[-84]^(b[-83]&b[-82])^c[-87];a.append(na);b.append(nb);c.append(nc)
g=stdin.read;s=g(1);[r() for x in range(1152)];
while(s):t=[];o=l([ord(s)])[0];o=[0 for i in range(8-len(o))]+o;[r() for x in range(8)];\
stdout.write(chr(int("".join(map(str,(map(lambda a,b:a^b,o,t)))),2))),;s=g(1)

8 lines is a little long for a sig :(

A marginally smaller, bz2 and base64ed version is:

emxpYi5kZWNvbXByZXNzKCIiInicbVHbbuMgEH33V1h9iIaERsbZbW0jvgSNJXxJwsaGCNNN+vcd
0ntVHjgzozNnYM4++Dlfnpfczmcf4lr2PCotcL3b6ALXoqi4RjmpyczdYPJTo2dzBusin+wSobMO
rkyXDTKW733Ir7l1+QmzE7cqMd/6rs3yNMMEqeTDwK+M8ci4CYf/WlCzNLzjF5VG1rvNiaegqjaW
Ai54idkw7vMArIlbcz6PboBe3z88YEsghMDWvKYE9Q7bjrL6BtUfEndG/aDDLShwlbCokd0EapSu
U9+lIGGJqwSCeKT5WBGvV9+GtJBwh6sEJfFIuHpEad7f6wyT3UfSMdl/JD3LDmqJg3XbMJpBLuoA
gklN//3caTDuMIIQf0uGMrsc7TTCQvtQZI9XE2haKxWQ0eqooItbq/1sre6n0YFnDDf+V+2KhOkV
/iluL8HGEfpjSE7D3d32nyejk3lLDBy+GEu+NabtuCc76fAyXW8/yF4AIQ63+CIiIik=

Still too long to fit in a facebook update :(

Syntax is sig.py key iv, eg:
echo "squeamish ossifrage" | sig.py brushie notsecret

Comments