bacon-cipher
An implementation of the Bacon's cipher.
The crate offers codecs that encode / decode and steganographers that hide / reveal encoded messages.
Available codecs:
-
CharCodec: A codec that encodes data of type
char
.The encoding is done by substituting with two given elements (
elem_a
andelem_b
) of typeT
.The substitution is done using the first version of the Bacon's cipher.
-
CharCodecV2: A codec that encodes data of type
char
.The encoding is done by substituting with two given elements (
elem_a
andelem_b
) of typeT
.The substitution is done using the second version of the Bacon's cipher.
Available steganographers:
-
LetterCaseSteganographer: Applies steganography based on the case of the characters.
E.g. Lowercase for Bacon's element A, capital for Bacon's element B.
-
MarkdownSteganographer: Applies steganography based on Markdown tags that surround elements.
E.g. Sourround an element with
**
for Bacon's element A and the rest of the elements are considered as Bacon's element B. -
SimpleTagSteganographer: Applies steganography based on HTML or XML tags that surround elements. (needs the feature
extended-steganography
)E.g. Sourround an element with
<b>
and</b>
for Bacon's element A and with<i>
and</i>
for Bacon's element B.
Encoding - Decoding
Encode a message to Bacon codes
use CharCodec;
use BaconCodec;
use FromIterator;
// Define a Bacon Codec that encodes using the characters 'A' and 'B'
let codec = new;
// This is the secret to encode
let secret: = "My secret".chars.collect;
// Get the encoded chars
let encoded_chars = codec.encode;
let encoded_string = String from_iter;
assert_eq!;
Decode Bacon codes
use CharCodec;
use BaconCodec;
use FromIterator;
// Define a Bacon Codec that encodes using the characters 'A' and 'B'
let codec = new;
// These are the encoded characters
let encoded_chars: = "ABABBBABBABAAABAABAAAAABABAAAAAABAABAABA".chars.collect;
// Retrieve the decoded chars
let decoded = codec.decode;
let string = String from_iter;
assert_eq!;
Steganography
Letter case
Disguise a hidden message into a public one
use CharCodec;
use LetterCaseSteganographer;
use ;
use FromIterator;
// Define a Bacon Codec that encodes using the characters 'A' and 'B'
let codec = new;
// Apply steganography based on the case of the characters
let s = new;
// This is the public message in which we want to hide the secret one.
let public_chars: = "This is a public message that contains a secret one".chars.collect;
// This is the message that we want to hide.
let secret_chars: = "My secret".chars.collect;
// This is the public message that contains the secret one
let disguised_public = s.disguise;
let string = String from_iter;
assert!;
Reveal a hidden message from a public one
use CharCodec;
use LetterCaseSteganographer;
use ;
use FromIterator;
// Define a Bacon Codec that encodes using the characters 'A' and 'B'
let codec = new;
// Apply steganography based on the case of the characters
let s = new;
// This is the public message that contains a hidden message
let public_chars: = "tHiS IS a PUbLic mEssAge thaT cOntains A seCreT one".chars.collect;
// This is the hidden message
let output = s.reveal;
let hidden_message = String from_iter;
assert!;
Markdown
Disguise a hidden message into a public one
use CharCodec;
use ;
use ;
use FromIterator;
// Define a Bacon Codec that encodes using the characters 'A' and 'B'
let codec = new;
// Apply steganography based on Markdown markers
let s = new.unwrap;
// This is the public message in which we want to hide the secret one.
let public = "This is a public message that contains a secret one";
// This is the message that we want to hide.
let secret_chars: = "My secret".chars.collect;
let output = s.disguise;
let string = String from_iter;
assert!;
Reveal a hidden message from a public one
use CharCodec;
use ;
use ;
use FromIterator;
// Define a Bacon Codec that encodes using the characters 'A' and 'B'
let codec = new;
// Apply steganography based on Markdown markers
let s = new.unwrap;
// This is the public message that contains a hidden message
let public = "T*h*i*s* *is* a *pu*b*l*ic m*e*ss*a*ge tha*t* c*o*ntains *a* se*c*re*t* one";
// This is the hidden message
let output = s.reveal;
assert!;
let string = String from_iter;
assert!;
Licence
At your option, under:
- Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (http://opensource.org/licenses/MIT)