From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f057fd3e6878bac X-Google-Attributes: gid103376,public From: "Craig Garrett" Subject: Re: Command line parameters Date: 1999/01/17 Message-ID: <01be426a$e4ad93e0$4304fbd1@longslide>#1/1 X-Deja-AN: 433776561 References: <77tm5p$kls$1@scelto.ts.kiev.ua> X-Complaints-To: support@newshosting.com X-Trace: news.siscom.net 916613128 209.251.4.67 (Sun, 17 Jan 1999 17:45:28 EDT) Organization: Newshosting NNTP-Posting-Date: Sun, 17 Jan 1999 17:45:28 EDT Newsgroups: comp.lang.ada Date: 1999-01-17T00:00:00+00:00 List-Id: Here is some code that does exactly what you want: ( I apologize about the indentation, cut and paste dont work that well) - Craig -- CreateOTP.ADA -- Author: Craig Garrett -- Ver 1.2 -- 28 MAY 1998 -- **************************************************************************** ** -- Creates a OneTimePad to encrypt ANY file. -- CREATEOTP [filename] [size] -- [filename] Specifies the name of the OneTimePad to be created. -- [size] Specifies the size of the OneTimePad in bytes. -- NOTE: The OneTimePad MUST be as large or larger than the file to be encrypted. -- After this OneTimePad has been used once, delete it. Do not use it twice. -- Also see ENCRYPT and DECRYPT for related commands. -- **************************************************************************** ** with Ada.Command_Line; with TEXT_IO; use TEXT_IO; with RANDOM; with Interfaces; with SEQUENTIAL_IO; procedure CreateOTP is package INT_IO is new TEXT_IO.INTEGER_IO (INTEGER); use INT_IO; package BYTE_FILE_IO is new SEQUENTIAL_IO(Interfaces.UNSIGNED_8); use BYTE_FILE_IO; procedure PRINT_HELP_INSTRUCTIONS is begin PUT("Creates a OneTimePad to encrypt ANY file."); NEW_LINE(2); PUT("CREATEOTP [filename] [size]");NEW_LINE(2); PUT(" [filename] Specifies the name of the OneTimePad to be created.");NEW_LINE; PUT(" [size] Specifies the size of the OneTimePad in bytes."); NEW_LINE(2); PUT("NOTE: The OneTimePad MUST be as large or larger than the file to be encrypted.");NEW_LINE; PUT("After this OneTimePad has been used once, delete it. Do not use it twice.");NEW_LINE(2); PUT("Also see ENCRYPT and DECRYPT for related commands.");NEW_LINE(2); end PRINT_HELP_INSTRUCTIONS; Command_Length : NATURAL := 0; -- Used to specify a max length in the GET call I : INTEGER := 0; -- Index for the for loop when writing the OneTimePad OTPLength : INTEGER := 0;-- Length in bytes of the OneTimePad to be created OTP_FILE : BYTE_FILE_IO.FILE_TYPE; -- File Pointer to the OneTimePad OTP_NAME : STRING(1..50) := " "; -- OneTimePad filename, 50 chars long just in case. OTP_BYTE : Interfaces.UNSIGNED_8 := 0; -- Unsigned 8-bit Integer, the byte written -- to the OneTimePad. begin if Ada.Command_Line.Argument_Count = 2 then OTP_NAME(1..Ada.Command_Line.Argument(1)'Last) := Ada.Command_Line.Argument(1); Command_Length := Ada.Command_Line.Argument(2)'Last; GET(Ada.Command_Line.Argument(2), OTPLength, Command_Length); CREATE(OTP_FILE, OUT_FILE, OTP_NAME); PUT("CREATING ONE-TIME-PAD: "); PUT(OTP_NAME); RANDOM.GET_TIME_SEED;--Generates a new seed based on the system clock for better randomness for I in 1..OTPLength loop --Generate a random unsigned, 8-bit integer, and write it to the file OTP_BYTE := Interfaces.Unsigned_8(RANDOM.NUMBER * 255.0); WRITE(OTP_FILE, OTP_BYTE); end loop; CLOSE(OTP_FILE); else -- Classic command line behavior, if no or incorrect command line parameters... PRINT_HELP_INSTRUCTIONS; end if; exception -- This is in case the given command line parameters are incorrect. when OTHERS => PRINT_HELP_INSTRUCTIONS; end CreateOTP;