Skip to content

Commit 935af2c

Browse files
committed
Added short flags and updated readme
1 parent e65fefb commit 935af2c

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ File Encryptor is a command-line tool written in Go that provides secure file en
1313
- Support for **all file types**: text, images (JPG, PNG), videos, spreadsheets, and more
1414
- Parallel processing for faster encryption and decryption of large files
1515

16-
**File Support Note**:
16+
**File Support Note**:
1717
- The tool supports all file types, including:
1818
- **Text**: TXT, CSV, JSON
1919
- **Media**: JPG, PNG, MP4
@@ -32,7 +32,7 @@ Example usage ensures seamless encryption and decryption without data corruption
3232

3333
2. Clone this repository:
3434
```bash
35-
git clone https://github.com/yourusername/file-encryptor.git
35+
git clone https://github.com/sd416/file-encryptor.git
3636
```
3737

3838
3. Navigate to the project directory:
@@ -42,7 +42,7 @@ Example usage ensures seamless encryption and decryption without data corruption
4242

4343
4. Build the project:
4444
```bash
45-
go build -o file-encryptor main.go
45+
go build -o file-encryptor cmd/file-encryptor/main.go
4646
```
4747

4848
## Usage
@@ -60,21 +60,29 @@ ssh-keygen -t rsa -b 4096 -f my_ssh_key
6060

6161
#### Encrypt a file using an RSA public key:
6262
```bash
63-
./file-encryptor -e --file <input_file> --key my_ssh_key.pub
63+
./file-encryptor -e --file <input_file> --key <public_key_file>
64+
# or using short flags
65+
./file-encryptor -e -f <input_file> -k <public_key_file>
6466
```
6567
Example:
6668
```bash
6769
./file-encryptor -e --file picture.jpg --key my_ssh_key.pub
70+
# or
71+
./file-encryptor -e -f picture.jpg -k my_ssh_key.pub
6872
```
6973
- The encrypted file will be saved as `picture.jpg.enc`.
7074

7175
#### Encrypt a file using a password:
7276
```bash
7377
./file-encryptor -e --file <input_file> --password <your_password>
78+
# or using short flags
79+
./file-encryptor -e -f <input_file> -p <your_password>
7480
```
7581
Example:
7682
```bash
7783
./file-encryptor -e --file document.pdf --password myStrongPassword123
84+
# or
85+
./file-encryptor -e -f document.pdf -p myStrongPassword123
7886
```
7987

8088
---
@@ -83,21 +91,29 @@ Example:
8391

8492
#### Decrypt a file using an RSA private key:
8593
```bash
86-
./file-encryptor -d --file <encrypted_file> --key my_ssh_key
94+
./file-encryptor -d --file <encrypted_file> --key <private_key_file>
95+
# or using short flags
96+
./file-encryptor -d -f <encrypted_file> -k <private_key_file>
8797
```
8898
Example:
8999
```bash
90100
./file-encryptor -d --file picture.jpg.enc --key my_ssh_key
101+
# or
102+
./file-encryptor -d -f picture.jpg.enc -k my_ssh_key
91103
```
92104
- The decrypted file will retain its original extension (e.g., `picture.jpg`).
93105

94106
#### Decrypt a file using a password:
95107
```bash
96108
./file-encryptor -d --file <encrypted_file> --password <your_password>
109+
# or using short flags
110+
./file-encryptor -d -f <encrypted_file> -p <your_password>
97111
```
98112
Example:
99113
```bash
100114
./file-encryptor -d --file document.pdf.enc --password myStrongPassword123
115+
# or
116+
./file-encryptor -d -f document.pdf.enc -p myStrongPassword123
101117
```
102118

103119
---
@@ -126,4 +142,3 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
126142
This tool is provided as-is, without any warranties. Always ensure you have backups of your important files before encryption.
127143

128144
---
129-

cmd/file-encryptor/main.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ import (
1313

1414
func main() {
1515
logger := logging.NewLogger()
16-
logger.LogDebug("Starting file encryptor") //Added debug log
16+
logger.LogDebug("Starting file encryptor")
1717

1818
encrypt := flag.Bool("e", false, "Encrypt the file")
1919
decrypt := flag.Bool("d", false, "Decrypt the file")
20+
21+
// Define both short and long flag names for file and key
2022
file := flag.String("file", "", "File to encrypt or decrypt")
21-
key := flag.String("key", "", "Path to the key file (public key for encryption, private key for decryption)")
23+
flag.StringVar(file, "f", "", "File to encrypt or decrypt (shorthand)") //Bind short flag to the same variable
24+
key := flag.String("key", "", "Path to the key file")
25+
flag.StringVar(key, "k", "", "Path to the key file (shorthand)") //Bind short flag to the same variable
26+
2227
password := flag.String("password", "", "Password for encryption/decryption (alternative to key file)")
28+
flag.StringVar(password, "p", "", "Password for encryption/decryption (shorthand)") //Bind short flag to the same variable
2329
flag.Parse()
24-
logger.LogDebug("Parsed command line flags") // Added debug log
30+
logger.LogDebug("Parsed command line flags")
2531

32+
// Use the flag values after parsing.
2633
if err := validateFlags(*encrypt, *decrypt, *file, *key, *password); err != nil {
2734
logger.LogError(err.Error())
2835
flag.Usage()
@@ -38,7 +45,7 @@ func main() {
3845
operation = "Decryption"
3946
outputFile, err = handleDecryption(*file, *key, *password, logger)
4047
}
41-
logger.LogDebugf("Operation: %s, Output file: %s", operation, outputFile) // Added debug log
48+
logger.LogDebugf("Operation: %s, Output file: %s", operation, outputFile)
4249

4350
if err != nil {
4451
logger.LogError(fmt.Sprintf("%v", err))
@@ -49,7 +56,7 @@ func main() {
4956
}
5057

5158
logger.LogInfo(fmt.Sprintf("File %s completed. Output file: %s", strings.ToLower(operation), outputFile))
52-
logger.LogDebug("File encryption/decryption completed") // Added debug log
59+
logger.LogDebug("File encryption/decryption completed")
5360
}
5461

5562
func validateFlags(encrypt, decrypt bool, file, key, password string) error {
@@ -58,15 +65,15 @@ func validateFlags(encrypt, decrypt bool, file, key, password string) error {
5865
}
5966

6067
if file == "" {
61-
return fmt.Errorf("please provide the --file argument")
68+
return fmt.Errorf("please provide the --file or -f argument")
6269
}
6370

6471
if key == "" && password == "" {
65-
return fmt.Errorf("please provide either --key or --password argument")
72+
return fmt.Errorf("please provide either --key or -k or --password or -p argument")
6673
}
6774

6875
if key != "" && password != "" {
69-
return fmt.Errorf("please provide either --key or --password, not both")
76+
return fmt.Errorf("please provide either --key or -k or --password or -p, not both")
7077
}
7178

7279
return nil
@@ -82,7 +89,7 @@ func handleEncryption(file, key, password string, logger *logging.Logger) (strin
8289
} else {
8390
encryptor, err = crypto.NewPasswordEncryptor(password)
8491
}
85-
logger.LogDebugf("Initialized encryptor: %T", encryptor) // Added debug log
92+
logger.LogDebugf("Initialized encryptor: %T", encryptor)
8693

8794
if err != nil {
8895
return "", fmt.Errorf("error initializing encryptor: %v", err)
@@ -103,7 +110,7 @@ func handleDecryption(file, key, password string, logger *logging.Logger) (strin
103110
} else {
104111
decryptor, err = crypto.NewPasswordDecryptor(password)
105112
}
106-
logger.LogDebugf("Initialized decryptor: %T", decryptor) // Added debug log
113+
logger.LogDebugf("Initialized decryptor: %T", decryptor)
107114

108115
if err != nil {
109116
return "", fmt.Errorf("error initializing decryptor: %v", err)

0 commit comments

Comments
 (0)