1 subcreatekey%=3000:subencrypt%=2000:subdecrypt%=1000
10 S$="yyyy"
20 KEY$="abc"
21 SL%=LEN(S$)
30 ds$=""
40 es$=""
41 gosub subencrypt%
42 print es$
43 s$ =es$
50 gosub subdecrypt%
60 print ds$
70 sleep 2000:end

1000 rem sub decrypt
1001 gosub subcreatekey%
1002 DS$=""
1003 FOR I%=1 TO SL%
1004 DS$=DS$+CHR$(ASC(MID$(S$,I%,1))-K%(I%))
1005 NEXT I%
1006 return

2000 rem sub encrypt
2001 gosub subcreatekey%
2002 for i%=1 to sl%
2003 es$ = es$ + CHR$(ASC(MID$(S$,I%,1))+K%(I%))
2005 next i%
2006 return

3000 rem sub create key
3001 DIM K%(SL%+1)
3002 KEYL%=LEN(KEY$)
3003 FOR I%=1 TO SL%
3004 II%=I%-(((I%-1)/KEYL%)*KEYL%)
3005 K%(I%)=ASC(MID$(KEY$,II%,1))
3006 NEXT I%
3007 return