-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxcrypt.adb
52 lines (41 loc) · 1.77 KB
/
xcrypt.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- Encryptuion/dectryption of files with the XOR cipher
-- Copyright (C) 2021 by PragmAda Software Engineering
-- Released under the terms of the GPL license version 3; see https://opensource.org/licenses
with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;
with Password_Line;
with PragmARC.Encryption.Simple_XOR;
procedure Xcrypt is
use PragmARC.Encryption;
procedure Usage; -- Displays usage instructions
procedure Usage is
-- Empty
begin -- Usage
Ada.Text_IO.Put_Line (Item => "usage: xcrypt <input file> [<output file>]");
Ada.Text_IO.Put_Line (Item => " en- and decrypts files with the XOR cipher");
Ada.Text_IO.Put_Line (Item => " prompts the user to enter a passphrase");
Ada.Text_IO.Put_Line (Item => " the output file, if not given, will have the same name as the input, with .xor appended");
end Usage;
use type Ada.Directories.File_Kind;
begin -- Xcrypt
if Ada.Command_Line.Argument_Count = 0 then
Usage;
return;
end if;
if not Ada.Directories.Exists (Ada.Command_Line.Argument (1) ) or else
Ada.Directories.Kind (Ada.Command_Line.Argument (1) ) /= Ada.Directories.Ordinary_File
then
Ada.Text_IO.Put_Line (Item => Ada.Command_Line.Argument (1) & " cannot be read");
Usage;
return;
end if;
Ada.Text_IO.Put_Line (Item => "Enter passphrase:");
Get_Passphrase : declare
Line : constant String := Password_Line;
Output : constant String :=
(if Ada.Command_Line.Argument_Count > 1 then Ada.Command_Line.Argument (2) else Ada.Command_Line.Argument (1) & ".xor");
begin -- Get_Passphrase
Simple_XOR.Crypt (Input_Name => Ada.Command_Line.Argument (1), Output_Name => Output, Key => Simple_XOR.To_Bytes (Line) );
end Get_Passphrase;
end Xcrypt;