From: "Craig Garrett" <cgarrett@siscom.net>
Subject: Re: Command line parameters
Date: 1999/01/17
Date: 1999-01-17T00:00:00+00:00 [thread overview]
Message-ID: <01be426a$e4ad93e0$4304fbd1@longslide> (raw)
In-Reply-To: 77tm5p$kls$1@scelto.ts.kiev.ua
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;
next prev parent reply other threads:[~1999-01-17 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-01-17 0:00 Command line parameters Igor Izvarin
1999-01-17 0:00 ` Craig Garrett [this message]
1999-01-17 0:00 ` David C. Hoos, Sr.
1999-01-18 0:00 ` Jerry van Dijk
[not found] <m-bartz-1701950936420001@macgalois.ee.memst.edu>
1995-01-17 17:10 ` Command Line Parameters fewellsj
1995-01-24 2:42 ` David Weller
1995-01-24 16:09 ` Tarjei Jensen
1995-01-26 12:54 ` Mats Weber
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox