Commit 38196b54 by kollo

add first Version of PGP.bas (not working yet)

parent 9bb12a3f
' Implementation of PGP (decodes PGP messages) written in X11-Basic
' (funktioniert noch nicht ....)
'
'
t$="-----BEGIN PGP MESSAGE-----"+chr$(10)
t$=t$+"Version: GnuPG v2.0.16 (GNU/Linux)"+chr$(10)
t$=t$+""+chr$(10)
t$=t$+"hQEMA1PUVhZb8UnsAQf+KS9PNvkWYFONnoStveMc4KwvGT7WlRFv/ZACvdyFsKDO"+chr$(10)
t$=t$+"icurhL57uh56KCof1m5drfftwjDQWgNyMy0cixqV/2WzeQgjZILE0Z1FDg7cgAbs"+chr$(10)
t$=t$+"UZvy2hmaJf0dhHEUziALotfUMhoSeHeObxmomzb7vovJv5tWDtQ9W+p2tbQ4tiin"+chr$(10)
t$=t$+"LAsJtwQhEVPNltootBteC0dTgOdISe6kfqUSoN3A22SiSUihmjxMPiiO6iZB8gBS"+chr$(10)
t$=t$+"hhfiSPa4khNwODncRe2BjqW+YQHf7L6CfLjx2S1BCSr+KWLmUnVdWSUonhHPF9mI"+chr$(10)
t$=t$+"E/q7t2uoBWg0iQgCjQubgYeqSUYN/xWpqAUX9O71zdKUAbVjjLVT0qTjNLLvms2H"+chr$(10)
t$=t$+"s4BDzHEqKeuGuMAWFzyfuW+VNofTxtcHhzrdjPuYi7sRL3YNUvqUpcGeKGyTApW2"+chr$(10)
t$=t$+"k/fd7U32av7Pq63NoKK2g3RFcyBUiSdNlNhW8TYS1NdMSMXNw1R9dWVgFmsLj2vs"+chr$(10)
t$=t$+"Rv89ufRiPbNLDXcx7CkRrTf13q0miy1850d6k5nt8qUFrnh4xQ=="+chr$(10)
t$=t$+"=z6Xk"+chr$(10)
t$=t$+"-----END PGP MESSAGE-----"+chr$(10)
SPLIT t$,chr$(10),0,a$,t$
SPLIT t$,chr$(10),0,a$,t$
SPLIT t$,chr$(10),0,a$,t$
t$=replace$(t$,chr$(10),"")
y$=@base64$(t$)
MEMDUMP varptr(y$),len(y$)
QUIT
s$=HASH$(t$)+MKL$(1)+chr$(2)+chr$(2)
MEMDUMP varptr(s$),len(s$)
f$=@radix64$(s$)
PRINT enclose$(f$)
y$=@base64$(f$)
MEMDUMP varptr(y$),len(y$)
QUIT
FUNCTION decode(a)
IF a>=asc("A") and a<=ASC("Z")
RETURN a-ASC("A")
ELSE if a>=asc("a") and a<=ASC("z")
RETURN a-ASC("a")+26
ELSE if a>=asc("0") and a<=ASC("9")
RETURN a-ASC("0")+52
ELSE if a=ASC("+")
RETURN 62
ELSE if a=ASC("/")
RETURN 63
ELSE if a=ASC("=")
RETURN 0
ENDIF
PRINT "ERROR: a=";a
RETURN -1
ENDFUNCTION
FUNCTION encode(a)
IF a<=25
RETURN asc("A")+a
ELSE if a<=51
RETURN asc("a")+a-26
ELSE if a<=61
RETURN asc("0")+a-52
ELSE if a=62
RETURN asc("+")
ELSE if a=63
RETURN asc("/")
ENDIF
PRINT "ERROR: a=";a
RETURN -1
ENDFUNCTION
FUNCTION base64$(a$)
LOCAL r$,i
r$=""
FOR i=0 to len(a$)/4-1
a=peek(varptr(a$)+4*i) and 255
b=peek(varptr(a$)+4*i+1) and 255
c=peek(varptr(a$)+4*i+2) and 255
d=peek(varptr(a$)+4*i+3) and 255
r$=r$+chr$(@decode(a)*4+(SHR(@decode(b),4) and 0x3))
IF d<>asc("=") or c<>asc("=")
r$=r$+chr$(@decode(b)*16+(SHR(@decode(c),2) and 0xf))
ENDIF
IF d<>asc("=")
r$=r$+chr$(@decode(c)*64+@decode(d))
ENDIF
NEXT i
RETURN r$
ENDFUNCTION
FUNCTION radix64$(g$)
LOCAL l,pointer,t$
t$=""
l=len(g$)
pointer=0
WHILE l>=3
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3) AND 0xfc)/4))
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3) AND 0x3)*16+(PEEK(VARPTR(g$)+pointer*3+1) and 0xf0)/16))
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3+1) AND 0xf)*4+(PEEK(VARPTR(g$)+pointer*3+2) and 0xc0)/64))
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3+2) AND 0x3f)))
SUB l,3
INC pointer
WEND
IF l ! handle the last 1 or 2 bytes
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3) AND 0xfc)/4))
IF l=1
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3) AND 0x3)*16))+"=="
ELSE
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3) AND 0x3)*16+(PEEK(VARPTR(g$)+pointer*3+1) and 0xf0)/16))
IF l=2
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3+1) AND 0xf)*4))+"="
ELSE
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3+1) AND 0xf)*4+(PEEK(VARPTR(g$)+pointer*3+2) and 0xc0)/64))
t$=t$+CHR$(@encode((PEEK(VARPTR(g$)+pointer*3+2) AND 0x3f)))
ENDIF
ENDIF
ENDIF
RETURN t$
ENDFUNCTION
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment