0//! OpenMessage
1//! Hides a message inside some text. Which can be recovered again by a key.
2//!
3//! Disclaimer: This programm does not cryptographically encrypt messages.
4//! it only obfuscates a message using XOR, and should not be used
5//! in any production environment.
6//!
7//! This project is only to experiment with permutations
8//! and byte manipulation.
9//!
10//! Copyright (C) 2025 adam@p-trace.com GPG: key.p-trace.com
11//!
12//! This program is free software: you can redistribute it and/or modify
13//! it under the terms of the GNU General Public License as published by
14//! the Free Software Foundation, either version 3 of the License, or
15//! any later version.
16//!
17//! This program is distributed in the hope that it will be useful,
18//! but WITHOUT ANY WARRANTY; without even the implied warranty of
19//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20//! GNU General Public License for more details.
21//!
22//! You should have received a copy of the GNU General Public License
23//! along with this program. If not, see <https://www.gnu.org/licenses/>.
25use std::fs::{self, read_to_string};
26use std::process::exit;
27use std::path::PathBuf;
29use clap::{CommandFactory, Parser};
31use obfuscator::Obfuscator;
33mod obfuscator;
36const CHUNK_SIZE: usize = 4;
37const MAGIC: [u8; 8] = [0x4f, 0x4d, 0x66, 0x6d, 0x74, 0x0, 0x0, 0x0]; // OMfmt
38const KEY_FN: &str = "key.om";
39const OUT_FN: &str = "output.txt";
41const CLI_ABOUT: &str = "Hides a message inside some text\n\
42 \n\
43 Encode:\n\
44 $ om container.txt -e message.txt\n\
45 \n\
46 Decode:\n\
47 $ om container.txt -d key.om";
50#[derive(Parser)]
51#[command(name = "OpenMessage")]
52#[command(about = CLI_ABOUT)]
53#[command(version, long_about = None)]
54struct Cli {
55 /// File path to the text file for the 'container'.
56 /// Where the message should be encoded/decoded from
57 container: PathBuf,
59 /// Encodes the message; needs the file path to the text file of the message
60 #[arg(short, long)]
61 encode: Option<PathBuf>,
63 /// Decodes the message; needs the file path to the keyfile.
64 /// from your current directory
65 #[arg(short, long)]
66 decode: Option<PathBuf>,
68 /// Outputs the decrypted message to a text file
69 #[arg(short, long)]
70 output: bool,
72 /// Doesn't print the message output to the console
73 #[arg(short, long)]
74 silent: bool,
76 /// Prints some debug information
77 #[arg(short, long)]
78 verbose: bool,
79}
82fn main() {
83 let cli = Cli::parse();
85 let container = match read_to_string(cli.container) {
86 Ok(v) => v,
87 Err(e) => {
88 eprintln!("{e}");
89 exit(1);
90 }
91 };
93 if cli.encode.is_some() {
94 let message = match read_to_string(cli.encode.unwrap()) {
95 Ok(v) => v,
96 Err(e) => {
97 eprintln!("[Error]: {e}");
98 exit(1);
99 }
100 };
102 Obfuscator::new(Some(message), container, KEY_FN.into(), cli.verbose).encode();
103 exit(0);
104 }
106 if cli.decode.is_some() {
107 let message = Obfuscator::new(None, container, cli.decode.unwrap(), cli.verbose).decode();
109 if cli.output {
110 match fs::write(OUT_FN, &message) {
111 Ok(_) => println!("Saved decrypted message to your current directory as '{}'", OUT_FN),
112 Err(e) => {
113 eprintln!("[Error]: {e}");
114 exit(1);
115 }
116 }
117 }
119 if !cli.silent {
120 println!("{}", message);
121 }
122 exit(0);
123 }
125 println!("Some args are missing! Help:");
126 let _ = Cli::command().print_help();
127 println!();
128 exit(0);
129}
index : openmessage
---