Out There In 1974 a coded message was sent into space from the Arecibo radio telescope in Puerto Rico. The message consisted of 1,679 ones and zeros. If received, it was hoped that an alien intelligence would decode the message to see the special image hidden within. 1,679 is the product of two prime numbers: 23 and 79. By arranging the code into 79 rows of 23 bits (or pixels), a picture is revealed:
The 'Out There' application allows students to create their own 'Arecibo' designs and to decode the images constructed by others.
1
Decoding Data files created and read by the application are simple text files that can be opened by any text editor. For example, the Arecibo file looks like this:
By looking at the properties of a message file, we can see its actual length:
The 'Size' is shown as 1,679 bytes. (Note that each “1” and “0” is saved as an ASCII character, not as a true bit.)
2
A simple factorising utility is included with the application:
Use the 2 prime factors to create the correct frame size for the image...
… oops, that's not right. 3
BB4W - Factorising code: REM Prevent resize SYS "GetWindowLong", @hwnd%, -16 TO ws% SYS "SetWindowLong", @hwnd%, -16, ws% AND NOT &40000 AND NOT &10000 VDU 23,22,400;320;16,16,16,0:REM User-defined Mode COLOUR 143:CLS:COLOUR 0 *ESC OFF *FONT Arial,16 REPEAT INPUT "Number to factorise : "n PROCfactorise(n):PRINT UNTIL 0 END DEF PROCfactorise(n) LOCAL a a=2 WHILE n>1 WHILE (n MOD a)=0 n=n DIV a PRINT a ENDWHILE a+=1 ENDWHILE ENDPROC
4
BB4W – 'Out There' code: REM Prevent resize SYS "GetWindowLong", @hwnd%, -16 TO ws% SYS "SetWindowLong", @hwnd%, -16, ws% AND NOT &40000 AND NOT &10000 VDU 23,22,640;640;16,16,16,0:REM User-defined Mode OFF COLOUR 143:CLS:COLOUR 0 REM *ESC OFF *FONT Arial,16 click=FALSE ON MOUSE:click=TRUE:RETURN ON ERROR:PROCerror:END REM File handling DIM Of% 75,filetype% 40,Fn% 255 !Of%=76:Of%!4=@hwnd%:Of%!28=Fn%:Of%!32=256:Of%!52=6:Of%!12=filetype% $filetype%="Text files"+CHR$0+"*.txt"+CHR$0 MAXprime=17 DIM prime(MAXprime):PROCsieve iw=0:ih=0:REM Pointers to prime(), image dimensions ir=12:REM Pixel size file$="":REM Image file name image$="":REM Binary image "1"s and "0"s ORIGIN 640,640 status=0 REPEAT TIME=0 MOUSE mx,my,mb key$=INKEY$(0) CASE status OF REM Initial menu WHEN 0 : PROCmenu(0):file$="":image$="":status=1 REM Animate rectangle WHEN 1 : PROClimits:IF click AND mb>0 click=FALSE:status=2 REM Show initial options (load or design) WHEN 2 : PROCmenu(1):status=3 REM Choose option WHEN 3 IF key$="1" THEN PROCloadimage IF file$<>"" PROCmenu(2):PROCshowimage:status=4 ENDIF IF key$="2" PROCmenu(3):image$=STRING$(prime(iw)*prime(ih),"0"):status=5 REM Choose to update or restart 5
WHEN 4 IF key$="1" status=0 IF key$="2" PROCmenu(3):PROCshowimage:status=5 REM Designing/updating image WHEN 5 IF key$="1" status=0 IF key$="2" PROCsaveimage PROCmakepattern ENDCASE WAIT 4-TIME UNTIL 0 END DEF PROCmakepattern LOCAL c,x,y,px,py,pb IF mb=0 ENDPROC IF (mb AND 4)=4 c=1:GCOL 0,0 ELSE c=0:GCOL 0,15 ORIGIN 640-prime(iw)/2*ir,640-prime(ih)/2*ir MOUSE px,py,pb:REM Obtain mouse co-ordinates relative to new origin x=px DIV ir:y=py DIV ir IF x>=0 AND x
=0 AND y"" n$=" ("+file$+")" ELSE n$="" CASE a OF WHEN 0 PROCcentre(0,-500,"Use the mouse to select an image size") WHEN 1 PROCcentre(0,-500,"1. Load an image") PROCcentre(0,-580,"2. Design an image") WHEN 2 PROCcentre(0,-500,"1. Restart") PROCcentre(0,-580,"2. Update"+n$+" design") WHEN 3 PROCcentre(0,-500,"1. Restart") PROCcentre(0,-580,"2. Save"+n$+" image") PROCcentre(0,580,"Create a design using the mouse") PROCcentre(0,500,"Left button to plot, right button to clear") ENDCASE ENDPROC
6
DEF PROCshowimage LOCAL x,y,a,over IF image$="" ENDPROC ORIGIN 640-prime(iw)/2*ir,640-prime(ih)/2*ir y=prime(ih)-1:over=FALSE:a=1 REPEAT x=0 REPEAT IF a>LEN(image$) over=TRUE:GCOL 0,6 ELSE GCOL 0,0 IF over OR MID$(image$,a,1)="1" RECTANGLEFILL x*ir,y*ir,ir x+=1:a+=1 UNTIL x>=prime(iw) y-=1 UNTIL y<0 ORIGIN 640,640 ENDPROC DEF PROCloadimage LOCAL R%,T%,X $Fn%=""+CHR$(0) SYS "GetOpenFileName",Of% TO R% T%=Fn%:WHILE ?T%<>0 T%+=1:ENDWHILE:?T%=13 IF R%=0 THEN ENDPROC IF INSTR($Fn%,".")=0 $Fn%+=".txt" file$=FNfilename X=OPENIN$Fn%:IF X=0 THEN ENDPROC image$="" REPEAT image$+=CHR$(BGET#X) UNTIL EOF#X CLOSE#X ENDPROC DEF PROCsaveimage LOCAL R%,T%,X,a $Fn%=file$+".txt"+CHR$(0) SYS "GetSaveFileName",Of% TO R% T%=Fn%:WHILE ?T%<>0 T%+=1:ENDWHILE:?T%=13 IF R%=0 THEN ENDPROC IF INSTR($Fn%,".")=0 $Fn%+=".txt" file$=FNfilename X=OPENOUT($Fn%) FOR a=1 TO LEN(image$) BPUT#X,ASC(MID$(image$,a,1)) NEXT CLOSE#X ENDPROC DEF FNfilename LOCAL i:i=LEN($Fn%) 7
WHILE MID$($Fn%,i,1)<>"\":i-=1:ENDWHILE =MID$($Fn%,i+1,LEN($Fn%)-i-4) REM Temp routine DEF PROCfill LOCAL x,y ORIGIN 640-prime(iw)/2*ir,640-prime(ih)/2*ir FOR y=0 TO prime(ih)-1 FOR x=0 TO prime(iw)-1 GCOL 0,RND(7)-1 RECTANGLEFILL x*ir,y*ir,ir NEXT NEXT ENDPROC REM Use mouse to select image dimensions DEF PROClimits LOCAL x,y,a,b x=ABS(mx DIV ir)*2 y=ABS(my DIV ir)*2 a=FNnearestprime(x) b=FNnearestprime(y) IF a<>iw OR b<>ih THEN PROCeor:iw=a:ih=b:PROCeor ENDIF ENDPROC REM Use EOR graphics to animate image bounds DEF PROCeor GCOL 3,3 RECTANGLE prime(iw)/2*ir,2+prime(ih)/2*ir,prime(iw)*-ir-2,prime(ih)*-ir-2 PRINTTAB(0,0);"Size: ";prime(iw);",";prime(ih);" " ENDPROC REM Find the nearest prime number to mouse x or y DEF FNnearestprime(n) LOCAL a,dist,p,d dist=9999:p=-1 FOR a=0 TO MAXprime d=ABS(prime(a)-n) IF d
r=INT(SQR(n)) a=2 WHILE okay AND a<=r IF (n MOD a)=0 okay=FALSE a+=1 ENDWHILE IF okay prime(aptr)=n:aptr+=1 n+=1 UNTIL aptr>MAXprime ENDPROC DEF PROCcentre(x,y,t$) LOCAL w,h:PROCstrpix(t$,w,h):VDU 5:MOVE x-w,y+h:PRINT t$:VDU 4 ENDPROC DEF PROCstrpix(T$,RETURN w,RETURN h) LOCAL size{}:DIM size{w%,h%} SYS "GetTextExtentPoint32",@memhdc%,T$,LEN(T$),size{} w=size.w%:h=size.h% ENDPROC DEF PROCerror CLS REPORT PRINT''"You've broken me." PRINT '"Type RUN and press ENTER, or close the window to quit." ENDPROC
9