(NOTE: Before using your RM make sure LAPLINK or any other program that uses the serial port is not loaded. Otherwise this other program could block the serial port) In combination with an Aware Radiation Monitor, AW-RAND generates a stream of random numbers out the serial port (COM port), into a file and/or to the display screen. The RM can be plugged into either a serial port or a LPT port (printer port). AW-RAND is copyrighted and is intended for the exclusive use of Aware Electronics customers. AW-RAND.EXE uses interrupt mode to trigger a scan of the PC's motherboard timer chip which is ticking at greater than 1.1 MHz. When reading the timer chip registers, AW-RAND takes an extra step to cancel out any non-linearity in a particular timer chip register bit. With each radiation "hit" from the RM unit, a bit in an output byte is set or not set according to the value of the timer scan. With each eight hits, the resulting byte is output to the TX pin of the serial port (any desired serial port, including the same serial port the RM monitor is plugged into) and/or to the screen and/or to a file. AW-RAND uses a large ring buffer. If your PC is slow or you use a low baud rate for output data, and the radiation level is very high, the ring buffer might overflow, in-which-case the program will issue a message and exit. Setup parameters are communicated to AW-RAND.EXE by way of command line arguments. Using a text editor (such as Aware's Aw-edit.exe) one can place the desired command line statement in a batch file and then start the program by running the batch file. One can type AW-RAND(enter) for a short help screen displaying the command line arguments AW-RAND recognizes which are described below. AW-RAND outputs random data from RM hits interacting with timer chip bits. Serial out defaults to port that RM uses (unless LPT). Use: AW-RAND (switches) Switches: RM port: -C#### or -L#### where #### is RM's port address in hex. Typically COM1=3f8, COM2=2f8, COM3=3e8, COM4=2e8 and LPT1=378, LPT2=278 -I# where # is IRQ(XT-AT IRQs). Normally COM 1&3=IRQ4; COM 2&4=IRQ3; LPT1=IRQ7; LPT2=IRQ5. Leave out -I switch, program uses default port IRQ. -O#### where #### is COM port address in hex for the data output. If you leave out ####, output goes to the -C#### port. No -O no COM output. If you desire random number output through a serial port, include this argument. Otherwise omit it. -B# where # is data output baud excluding last two digits i.e. 300 baud=3 1200 baud=12, 19200 baud=192, 115200 baud=1152, etc. This arg. is needed only if you include the above mentioned -O arg. -M# where # is maximum # of random numbers to output. If you leave out the -M switch or use -M0, program keeps running until the ESC key is pressed. -S# where # is 0 1 2 or 3. Screen output 0=none, 1=hex, 2=decimal, 3=binary If you leave out the -S switch, program outputs hexadecimal. -F\path\\file to place data using -S format unless you include the -9 arg. (see below) or unless you want binary numbers (see below). Add ~# to end of -F arg wherein # equals one of the following characters to add: C = Carriage Return after each number or groups of numbers; L = Add Carriage Return-Line feed; N = No Carriage or Line feed; If you want the numbers in the file to be pure binary numbers, add B after the ~. -9 will constrain file output to random numbers from 0 to 9. Constrain output from 0 to 99 by adding the -99 switch; (See explanations below). Add -P to pad the numbers with zeros. ***ESC or CTRL-BREAK stops*** Futher explanation of the above args with example command lines: The arg. -C#### indicates the COM port for the RM. Example: The RM is plugged into COM1: AW-RAND -C3F8 The -C3f8 tells the program the RM is plugged into the serial port with the address 3F8 (COM 1). The port address can be any COM port address in the PC. The four common COM port addresses found in most PCs are COM1 = address 3F8; COM2 = 2F8; COM3 = 3E8; COM4 = 2E8. Our standard radiation gathering software AW-SRAD.EXE included with each RM can help you determine which COM port the RM is plugged into. (See the RM-60 manual). By default the program will use the default IRQ number for the RM input COM port. Normally COM1 uses IRQ 4; COM2 uses IRQ 3; COM3 uses IRQ 4 and COM4 uses IRQ 3. If you are using a COM port with a non-standard IRQ, add the -I(number) arg. where (number) equals the IRQ. Example: Use COM port with address 3F8 (COM1) with an IRQ of 5: AW-RAND -C3F8 -I5 -O#### arg. indicates the COM port for serial port date output. You would include this arg. if you wanted the program to output the random numbers to a serial port into which you have plugged another PC for reading of the random numbers. If you include the -O arg. with no #### part, serial port data out goes to the -C#### COM port i.e. the same COM port that the RM is plugged into, unless you are using a LPT port for the RM input (see below) in which case you must include the -O#### arg. If you leave out the -O switch, program doesn't output data to a COM port. If you include the -O arg. you should include the -B baud rate arg. (see the description of the -B arg. at top of this readme file). Example: The RM is plugged into COM1 and you want serial data output to go to COM 2 with a baud rate of 9600: AW-RAND -C3F8 -O2F8 -B96 If a LPT port is used for RM input, include the -L#### switch where #### is the LPT port address in HEX. On most PCs LPT 1 = address 378; LPT2 = address 278. Example: The RM is plugged into LPT 1: AW-RAND -L378 Note the standard LPT port IRQ numbers on most PCs are as follows: LPT1 address 378 uses IRQ 7. LPT2 address 278 uses IRQ 5. You can override the default LPT port IRQs with the -I arg. (see above). You have four choices for the display screen format. The display screen args are -S# where # is 0 1 2 or 3. 0 = No screen output; 1 = hexadecimal, 2 = decimal, 3 = ASCII binary. If you leave out the -S arg, program outputs hexadecimal. Example: You want ASCII binary screen display output: AW-RAND -S3 To store the random numbers in a file include the -F############### arg. where ############### is the path\filename to place the random number data. If you leave out the path, the program will create the file in the current default directory (folder). Note that if the file already exists the program will first erase it. The random number output format for the file will be the same as the -S screen format arg. unless you want binary numbers (see below) or unless you include the -9 or -99 arg. (see below). During file output, by default the program will use the -S arg. format and follow each random number with a Carriage Return-Line Feed. Example: Place the random numbers in a file with the path and file name C:\MYDATA\MYRAND1.TXT using the -S arg. format: AW-RAND -FC:\MYDATA\MYRAND1.TXT If you would rather have nothing but numbers in the file (no carriage returns or line feeds), end the -F arg. string with the ~ (tilde) character followed by N. Example: AW-RAND -FC:\MYDATA\MYRAND.TXT~N With the file arg. if you include ~(number) the program will insert a CR-LF (carriage return line feed) after so many numbers. Example: Add a CR-LF after every four numbers: AW-RAND -FC:\MYDATA\MYRAD.TXT~4 Note the ~(number) also applies to the display screen output. If you would rather have AW-RAND place raw binary numbers in the file, append ~B to the end of the -F arg. Example: Place the data in the file using raw binary numbers, overriding the -S arg. format: AW-RAND -FC:\MYDATA\MYRAND1.TXT~B Note binary numbers can't be displayed by normal text editors and also no carriage returns or linefeeds are added i.e the file is filled with a stream of raw binary numbers. If you want numbers constrained to the decimal numbers 0 to 9 add the -9 arg. and for decimal numbers 0 to 99 add the -99 arg. Example: Constrain the numbers to the decimal number set 0 to 9: AW-RAND -FC:\MYRAND1.TXT -9 Constrain numbers from 0 to 99: AW-RAND -FC:\MYRAND1.TXT -99 Note the -9 and -99 also constrain the numbers displayed on the screen to the numbers 0 to 9 or 0 to 99. You can also add P to the end of the -99 arg. for zero padding of the numbers. Example: Place in the file decimal numbers from 0 to 99 and pad any numbers below 10 with a zero i.e. a random number 8 would be written to the file as 08: AW-RAND -FC:\MYRAND\MYDATA -99P Note the added P arg. will also be applied to the -S screen format. OK that pretty much covers the command line args. It may seem a little complicated at the moment but once you experiment with the different args. they will become more obvious. Here are some complete examples: Use COM 1 for the RM, display the numbers on the screen in decimal format, place the numbers in a file named MYRAND.TXT using the same directory that the AW-RAND program is started from: AW-RAND -C3F8 -S2 -FMYRAND.TXT Program output to screen and file: 1 14 6 78 222 14 etc. Note since each number is generated within the program as a byte (eight bits) the decimal numbers will be constrained to the binary number set 0 to 255. 255 is the largest number a byte can hold. OK now lets say you want numbers constrained to the number set 0 to 9 and you want a CR-LF inserted after every 8 numbers: AW-RAND -C3F8 -9 -FMYRAND.TXT~8 Program output to screen and file: 10984732 65932409 35910923 45560321 87254012 etc. Now lets say you want two sets of ASCII binary numbers to the screen and to the file: AW-RAND -C3F8 -S3 -FMYRAND.TXT~2 Program output to screen and file: 0100110211011001 0110110021011001 0100110000000110 1101110011011001 etc. OK lets say you want numbers constrained from 0 to 99 for both screen and file output: AW-RAND -C3F8 -FMYRAND.TXT -99 Program output to screen and file: 4 26 89 5 23 etc. Lets say you want the same but with zero padding: AW-RAND -C3F8 -FMYRAND.TXT -99P Program output to screen and file: 04 26 89 05 23 etc. Lets say you want the same but in addition you want the numbers output to COM2 port with baud rate of 9600: AW-RAND -C3F8 -FMYRAND.TXT -99P -O2F8 -B96 Note in this case the numbers that are output through the COM port will be constrained from 0 to 99 but the COM output numbers will be binary. OK That's enough examples. Note if you want to read the output file with another program while AW-RAND is running, you should OPEN the file for reading with full SHARE. (Most editors or spreadsheets will try to open the file without share semaphore and the OS will block them. You could copy the active file to a file with a different name and then view that copy while Aw-srad.exe continues adding to the first). A deeper explanation of the -9 arg. constrain output from digits 0 to 9: Some users prefer output between 0 and 9 inclusive. As indicated above, by adding the -9 switch the program will use the timer scan info. to generate output numbers contrained to the range 0 to 9. Once enough 'hits' from the RM have been received for the generation of a 4 bit number (a number between 0 and 16), if the result is within the range 0 to 9 the number is output. If the number is above 9 it is rejected. The program uses this procedure to maintain random distribution of output numbers between 0 and 9. A deeper explanation of the -99 arg. constrain output to digits 0 to 99: Some users prefer output between 0 and 99 inclusive. As indicated above, by adding the -99 switch the program will do so. Once enough 'hits' have been received from the RM unit for the generation of an 8 bit number (a number between 0 and 255), if the result is within the range 0 to 99 the number is output. If the number is above 99, 100 is subtracted from it and if the result is then within the range 0 and 99 it is output. Otherwise the number is rejected. The program uses this procedure to maintain radom distribution of output numbers within the range 0 to 99. Note with the -9 switch and -S2 hexadecimal screen output mode, the number output will be constrained to the hexadecimal set: 00 01 02 03 04 05 06 07 08 09 and with the -S1 decimal screen output: 0 1 2 3 4 5 6 7 8 9. With the -99 switch and -S2 hexadecimal screen output mode, number output will be constrained to the hexadecimal range between 00 and 63 i.e. 0 will print as 00, 10 as 0A, 27 as 1B, 90 as 5A, etc. More on the raw binary output: As regards raw binary output (either to the file and\or to a COM port) and the -9 or -99 switch, each binary output number will contain the full 8 bits in the output byte but will be constrained to the range 0 to 9 or 0 to 99 and the top unused bits of the output byte will be zero. More on the baud rate arg. for COM port output: For the COM port data output, there is a baud rate switch -B# where # is baud excluding last two digits i.e.: 300 baud= -B3 600 baud= -B6 1200 baud= -B12 2400 baud= -B24 4800 baud= -B48 9600 baud= -B96 19200 baud= -B192 28800 baud= -B288 57600 baud= -B576 115200 baud= -B1152 If you include the baud switch, the program sets the UART data format register to 8 data bits, 1 stop bit, no parity. If you leave out the baud switch, the program sends data to the COM port without setting the baud and data format, which allows user to first use DOS MODE (or other program) to set the baud and format. For example, if you send the data to a COM port connected to a modem, you could first (from a batch file) run a program that sends a setup string to the modem, dials a number, waits for carrier detect then exits back to the batch file, which then starts AW-RAND. Since AW-RAND doesn't use modem flow control, but rather, sends data to the COM port when the COM port UART says its transmitter buffer is empty, you should set up the modem to operate in hybrid mode or dumb mode and also perhaps set high the DTR and RTS modem control lines. (If you need help with using a modem, contact us. We can E-mail you a freeware modem dialer program). WHEN USING THE SAME COM PORT FOR RM INPUT AND DATA OUTPUT: COM port data output is on the serial port's TX (transmitter) pin. This you would connect to the RX (receiver) pin of the the PC that is receiving your COM port output data. You also need to connect the signal ground lead of the two PC's serial ports. The RS-232 to MOD adapters included with each RM from Aware include six leads in the RJ-12 jack. The RM cable only connects to the middle four. One of these middle four is the signal ground. Looking at back of the adapter with the MOD plug key facing up, starting from the right side the contact wires are: Chassis Ground, Negative, Positive, Signal, Signal Ground, TX. As indicated above, for serial port data output to another PC you need the TX and signal ground to connect to the other PC's serial port. You also need to pass the Negative, Positive, Signal and Signal ground on to the RM. Perhaps the easiest method to accomplish this is to either use a breakout box, or purchase perhaps from Radio Shack, a six conductor telephone cable with a six conductor MOD plug on one end and bare wires on the other. Also purchase a RJ-12 six conductor surface mount box. Plug six conductor cable into the Aware RM adapter. Wire the surface mount box MOD jack to the leads needed by the RM and plug the RM cable into the surface mount box MOD jack. Use surface mount box terminals to make your connection to the TX and Signal ground leads. You could use an ohm meter to verify your connections. If you get them wrong, you wont hurt anything. The RM has protection diodes that protect it against incorrectly connected RS-232 leads. (Phone or E-Mail us for more info.) MORE ON THE OUTPUT DATA TO COM PORT: Note the program does not respond to flow control commands from the other PC's serial port. It just sends the serial data out as fast as the radiation hit rate and the serial port UART baud rate will allow. If the receiving PC is very slow or is using a poorly designed communications program such that it misses some bytes, it makes no difference since the data is pure random in nature. Note you can setup the receiving PC's serial port using dos MODE command (type MODE /? for help) then on the receiving PC type: COPY COM1 FILENAME.TXT (Copy the data coming in the COM1 port to a file named FILENAME.TXT). If you tell AW-RAND program to use a slow output baud rate and you have a very high hit rate, as indicated above, the ring buffer will fill. Notice when you remove the radioactive source from the RM unit, numbers keep coming out at maximum baud rate until the ring buffer empties (unless you overflow the ring buffer in which case the program exits). From www.aw-el.com/random.htm: Besides testing equipment another use for a large file of pure random numbers includes uncrackable data scrambling. One can generate a large file of pure random numbers with Aw-rand + the Aware RM unit. A copy of this file is then placed on a floppy or burned onto a CD and given to the receiving person. Now to send a scrambled file to the person, XOR each byte in the file with a byte from the random number file. The resulting output file will be completely scrambled and uncrackable. Send this file to the receiver and he then XORs it with the same set of random numbers. We include on disk a program named AW-SRAM.EXE (see source code below). Here is how you could use Aw-sram.exe. First generate a raw binary number file with Aw-rand.exe (AW-RAND -C3F8 -FMYRAND.BIN~B). Let Aw-rand run long enough such that the raw binary number file is larger than the largest file you want to scramble. Now make a copy of this file (COPY MYRAND.BIN HISRAND.BIN) and copy HISRAND.BIN to a floppy or burn it onto a CD. Give the copy to your receiver. Now you have a file named MYRAND.BIN and he has an exact copy named HISRAND.BIN. Now lets say you write a letter to him with your word processor and you save this letter to a file named MYLETTER.DOC. OK so now you have your copy of the random number file (MYRAND.BIN) and your document file (MYLETTER.DOC). To scramble the MYLETTER.DOC, at the DOS command prompt type: AW-SRAM MYLETTER.DOC MYRAND.BIN MYLETTER.SCR Aw-sram will then scramble MYLETTER.DOC by XORing all the bytes in it with the random numbers in MYRAND.BIN and ouput the result to a file named MYLETTER.SCR. OK so now MYLETTER.SCR is completely scrambled and is uncrackable. E-Mail MYLETTER.SCR to your receiver as an attached file (or send it to him on a floppy, etc.). Next he would unscramble it by typing at the command prompt (followed by ENTER key): AW-SRAM MYLETTER.SCR HISRAND.BIN MYLETTER.DOC (or any output file name he wants). OK so now the scrambled file (MYLETTER.SCR) has been XORed with the same set of random numbers used to scramble it (HISRAND.BIN), and therefore his output file MYLETTER.DOC will be an exact copy of your MYLETTER.DOC. On can re-use the MYRAND.BIN and HISRAND.BIN with different document files (or any other kind of file), as many times as wanted since any and all scrambled files are completely uncrackable. Of course it goes without saying if any other person gets a copy of the random number file, he also could unscramble the files. Here is the example C source code, some of which is used by AW-SCRAM.EXE: (Include necessary include files) int handin=0; int handout=0; int randin=0; void close_hands(void) { if(handin) _close(handin); if(handout) _close(handout); if(randin) _close(randin); } void bye(char *name,int show_errno,int close_hand) { printf("\007\nCould not open: %s",name); if(show_errno) { printf("\n%s\n",sys_errlist[errno]); } if(close_hand) close_hands(); exit(1); } void main(void) { unsigned long ul,in_size; static unsigned char inbyte; static unsigned char outbyte; static unsigned char randbyte; if(_argc<4) { printf("\nUsage: AW-SCRAM filein randomfile fileout"); exit(1); } if( (handin=_open(_argv[1],O_RDONLY )) == -1) bye(_argv[1],1,0); if( (randin=_open(_argv[2],O_RDONLY )) == -1) bye(_argv[2],1,1); if( (handout=_creat(_argv[3],FA_ARCH)) == -1) bye(_argv[3],1,1); in_size=filelength(handin); if(in_size>filelength(randin)) { printf("\n\007Input file: %s\nIs Larger Than\nRandom number file: %s",_argv[1],_argv[2]); close_hands(); exit(1); } for(ul=0l;ul