Code for the paper Generating Steganographic Text with LSTMs. The LSTM is based on the Word Language Model example from PyTorch (http://pytorch.org/).
- Latest NVIDIA driver
- CUDA 8 Toolkit
- cuDNN
- PyTorch
A small sample of Penn Treebank and Tweets. pre-process.py
is tokenization of punctuation.
python main.py --cuda --nhid 600 --nlayers 3 --epochs 6 --data './data/tweets' --save './models/twitter-model.pt'
For the full list of arguments, check the PyTorch example README.
One of our key original contributions. After we train our model, we generate words and restrict the output based on the secret text. generate.py
is modified such that it takes the secret text and modifies the probabilities based on the "bins" as described in our paper.
If replication factor is bigger than 1, the encoding/decoding is non-deterministic.
Example generation with 4 bins:
python generate.py --data './data/tweets' --checkpoint './models/twitter-model.pt' --cuda --words 1000 --temperature 0.8 --bins 8 --common_bin_factor 4 --num_tokens 20 --secret_file './demo/secret_file.txt' --outf './outputs/stegotext.txt' --replication_factor 3 --save_bins --save_corpus
add --random if non existing './demo/secret_file.txt'
See the arguments in generate.py
or refer to the PyTorch example README.
Given that we know the seed that was used to generate to stegotext, we can decode it.
python decoder.py --data './data/tweets' --checkpoint './models/twitter-model.pt' --cuda --bins 8 --model_char_nn './tools/rnn_char/models/wiki.pt' --encoded_file './outputs/stegotext.txt' --replication_factor 3 --save_corpus --next_character 10 --save_bins --num_tokens 20 --common_bin_factor 4
See the arguments in decoder.py
This code is based on tbfang/steganography-lstm. The character-level rnn is based on Practical PyTorch: Generating Shakespeare with a Character-Level RNN