Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a10d974b2 | |||
| 7e04896394 |
10
README.md
10
README.md
@@ -164,11 +164,9 @@ Offset | Size | Field | Description
|
|||||||
4 | 2 | Version | Format version (currently 1)
|
4 | 2 | Version | Format version (currently 1)
|
||||||
6 | 32 | Pad Checksum | Binary pad checksum (32 bytes)
|
6 | 32 | Pad Checksum | Binary pad checksum (32 bytes)
|
||||||
38 | 8 | Pad Offset | Offset in pad file (uint64_t)
|
38 | 8 | Pad Offset | Offset in pad file (uint64_t)
|
||||||
46 | 2 | Filename Length | Original filename length (uint16_t)
|
46 | 4 | File Mode | Original file permissions (uint32_t)
|
||||||
48 | var | Original Filename | Original filename string
|
50 | 8 | File Size | Original file size (uint64_t)
|
||||||
var | 4 | File Mode | Original file permissions (uint32_t)
|
58 | var | Encrypted Data | XOR-encrypted file contents
|
||||||
var | 8 | File Size | Original file size (uint64_t)
|
|
||||||
var | var | Encrypted Data | XOR-encrypted file contents
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### .otp.asc File Format (ASCII Armored)
|
### .otp.asc File Format (ASCII Armored)
|
||||||
@@ -185,7 +183,7 @@ Pad-Offset: <decimal-offset-value>
|
|||||||
-----END OTP MESSAGE-----
|
-----END OTP MESSAGE-----
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** ASCII armored files lose original filename and permission metadata.
|
**Note:** ASCII armored files do not preserve original file permissions metadata.
|
||||||
|
|
||||||
## Usage Examples
|
## Usage Examples
|
||||||
|
|
||||||
|
|||||||
BIN
TropicOfCancer-HenryMiller.txt.otp
Normal file
BIN
TropicOfCancer-HenryMiller.txt.otp
Normal file
Binary file not shown.
83
otp.c
83
otp.c
@@ -151,6 +151,14 @@ int interactive_mode(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int command_line_mode(int argc, char* argv[]) {
|
int command_line_mode(int argc, char* argv[]) {
|
||||||
|
// Check for help flags first
|
||||||
|
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--h") == 0 ||
|
||||||
|
strcmp(argv[1], "-help") == 0 || strcmp(argv[1], "--help") == 0 ||
|
||||||
|
strcmp(argv[1], "help") == 0) {
|
||||||
|
print_usage(argv[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(argv[1], "generate") == 0 || strcmp(argv[1], "-g") == 0) {
|
if (strcmp(argv[1], "generate") == 0 || strcmp(argv[1], "-g") == 0) {
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
printf("Usage: %s generate|-g <size>\n", argv[0]);
|
printf("Usage: %s generate|-g <size>\n", argv[0]);
|
||||||
@@ -374,44 +382,45 @@ char* find_pad_by_prefix(const char* prefix) {
|
|||||||
char* matches[100]; // Store up to 100 matches
|
char* matches[100]; // Store up to 100 matches
|
||||||
int match_count = 0;
|
int match_count = 0;
|
||||||
|
|
||||||
// Check if it's a number (for interactive menu selection)
|
// Always try hex prefix matching first
|
||||||
// Only treat as number if it's a single digit (1-9) to avoid conflicts with hex prefixes
|
size_t prefix_len = strlen(prefix);
|
||||||
char* endptr;
|
while ((entry = readdir(dir)) != NULL && match_count < 100) {
|
||||||
int selection = strtol(prefix, &endptr, 10);
|
// Skip . and .. entries, and only process .pad files
|
||||||
if (*endptr == '\0' && selection > 0 && selection <= 9 && strlen(prefix) == 1) {
|
if (entry->d_name[0] == '.') continue;
|
||||||
// It's a number, find the nth pad
|
if (!strstr(entry->d_name, ".pad")) continue;
|
||||||
int current = 0;
|
if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad"
|
||||||
rewinddir(dir);
|
|
||||||
while ((entry = readdir(dir)) != NULL && match_count == 0) {
|
// Compare prefix with the filename (checksum part)
|
||||||
// Skip . and .. entries, and only process .pad files
|
if (strncmp(entry->d_name, prefix, prefix_len) == 0) {
|
||||||
if (entry->d_name[0] == '.') continue;
|
matches[match_count] = malloc(65);
|
||||||
if (!strstr(entry->d_name, ".pad")) continue;
|
strncpy(matches[match_count], entry->d_name, 64);
|
||||||
if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad"
|
matches[match_count][64] = '\0';
|
||||||
|
match_count++;
|
||||||
current++;
|
|
||||||
if (current == selection) {
|
|
||||||
matches[match_count] = malloc(65);
|
|
||||||
strncpy(matches[match_count], entry->d_name, 64);
|
|
||||||
matches[match_count][64] = '\0';
|
|
||||||
match_count = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// Find pads that start with the prefix
|
|
||||||
size_t prefix_len = strlen(prefix);
|
// If no hex prefix matches and it looks like a small number, try number selection
|
||||||
while ((entry = readdir(dir)) != NULL && match_count < 100) {
|
if (match_count == 0) {
|
||||||
// Skip . and .. entries, and only process .pad files
|
char* endptr;
|
||||||
if (entry->d_name[0] == '.') continue;
|
int selection = strtol(prefix, &endptr, 10);
|
||||||
if (!strstr(entry->d_name, ".pad")) continue;
|
if (*endptr == '\0' && selection > 0 && selection <= 100) {
|
||||||
if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad"
|
// It's a number, find the nth pad
|
||||||
|
int current = 0;
|
||||||
// Compare prefix with the filename (checksum part)
|
rewinddir(dir);
|
||||||
if (strncmp(entry->d_name, prefix, prefix_len) == 0) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
matches[match_count] = malloc(65);
|
// Skip . and .. entries, and only process .pad files
|
||||||
strncpy(matches[match_count], entry->d_name, 64);
|
if (entry->d_name[0] == '.') continue;
|
||||||
matches[match_count][64] = '\0';
|
if (!strstr(entry->d_name, ".pad")) continue;
|
||||||
match_count++;
|
if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad"
|
||||||
|
|
||||||
|
current++;
|
||||||
|
if (current == selection) {
|
||||||
|
matches[match_count] = malloc(65);
|
||||||
|
strncpy(matches[match_count], entry->d_name, 64);
|
||||||
|
matches[match_count][64] = '\0';
|
||||||
|
match_count = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user