Dualcone is a Ruby source code protection system. Dualcone uses symmetric encryption to protect your source code.

Dualcone is a self-contained gem. It brings along its own copy of the lightweight cryptographic library, libhydrogen.

Dualcone supports GNU + Linux and other Unix-like operating systems. Windows is not supported.


Add this gem to your application's Gemfile:

gem 'dualcone'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install dualcone

You need to have a C compiler and make installed on your system to be able to build this gem's native code and the included version of libhydrogen.


  1. Generate a secret encryption key.

    require 'dualcone'
    => "764888c92f3059c88524225b622cd178856877cf3537230a9d7f5b5b6d8850c5"
  2. Place your encryption key in the DUALCONE_HEX_KEY environment variable:

    $ export DUALCONE_HEX_KEY="8c8f91f84d8e554dc03277ce2f038af95cd932e2b65011969e77d3ac18d7bdd9"

    This environment variable is required for both encrypting files as well as running already-encrypted files.

  3. Encrypt your Ruby source code file(s).

    :warning: Your source code file will be modified in-place. This is a one-way operation! :warning:

    For example, let's say we have a file named hello.rb with the following contents:

    puts 'Hello, world!'

    You can encrypt this file using Dualcone.encrypt(path)


    The entire contents of the file hello.rb will be replaced with a call to Dualcone.run(code):

    require 'dualcone'
  4. Finally, test your encrypted code by running it.

    $ ruby hello.rb


  1. git clone [email protected]:t-richards/dualcone.git to clone the repo.
  2. bin/setup to install dependencies and fetch git submodules.
  3. bin/rake compile to build the gem's native extensions.
  4. bin/rspec to run the tests.
  5. bin/rubocop to check code style.

You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bin/rake install. To release a new version, update the version number in version.rb, and then run bin/rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.


  • [x] Runnable trivial ruby script
  • [ ] Runnable non-trivial ruby script
  • [ ] Runnable sinatra app
  • [ ] Runnable rails app


Bug reports and pull requests are welcome on GitHub at https://github.com/t-richards/dualcone.


The gem is available as open source under the terms of the ISC License.