Skip to content

Commit

Permalink
Tag the v0.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Apr 30, 2014
0 parents commit a1ecb26
Show file tree
Hide file tree
Showing 14 changed files with 886 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
@@ -0,0 +1,2 @@
# Automatically normalize line endings for all text-based files
* text=auto
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
# Coverage report
coverage

# Installed npm modules
node_modules

# Folder view configuration files
.DS_Store
Desktop.ini

# Thumbnail cache files
._*
Thumbs.db

# Files that might appear on external disks
.Spotlight-V100
.Trashes
18 changes: 18 additions & 0 deletions .travis.yml
@@ -0,0 +1,18 @@
language: node_js
node_js:
- "0.10"
before_script:
- "npm install -g grunt-cli"
# Narwhal uses a hardcoded path to openjdk v6, so use that version
- "sudo apt-get update -qq"
- "sudo apt-get install -qq openjdk-6-jre"
- "PACKAGE=rhino1_7R3; wget http://ftp.mozilla.org/pub/mozilla.org/js/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
- "PACKAGE=rhino1_7R3; echo -e '#!/bin/sh\\njava -jar /opt/'$PACKAGE'/js.jar $@' | sudo tee /usr/local/bin/rhino && sudo chmod +x /usr/local/bin/rhino"
- "PACKAGE=ringojs-0.9; wget http://ringojs.org/downloads/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
- "PACKAGE=ringojs-0.9; sudo ln -s /opt/$PACKAGE/bin/ringo /usr/local/bin/ringo && sudo chmod +x /usr/local/bin/ringo"
- "PACKAGE=v0.3.2; wget https://github.com/280north/narwhal/archive/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
- "PACKAGE=narwhal-0.3.2; sudo ln -s /opt/$PACKAGE/bin/narwhal /usr/local/bin/narwhal && sudo chmod +x /usr/local/bin/narwhal"
# If the enviroment stores rt.jar in a different directory, find it and symlink the directory
- "PREFIX=/usr/lib/jvm; if [ ! -d $PREFIX/java-6-openjdk ]; then for d in $PREFIX/java-6-openjdk-*; do if [ -e $d/jre/lib/rt.jar ]; then sudo ln -s $d $PREFIX/java-6-openjdk; break; fi; done; fi"
script:
"grunt ci"
61 changes: 61 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,61 @@
module.exports = function(grunt) {

grunt.initConfig({
'shell': {
'options': {
'stdout': true,
'stderr': true,
'failOnError': true
},
'cover': {
'command': 'istanbul cover --report "html" --verbose --dir "coverage" "tests/tests.js"'
},
'test-narwhal': {
'command': 'echo "Testing in Narwhal..."; export NARWHAL_OPTIMIZATION=-1; narwhal "tests/tests.js"'
},
'test-phantomjs': {
'command': 'echo "Testing in PhantomJS..."; phantomjs "tests/tests.js"'
},
// Rhino 1.7R4 has a bug that makes it impossible to test in.
// https://bugzilla.mozilla.org/show_bug.cgi?id=775566
// To test, use Rhino 1.7R3, or wait (heh) for the 1.7R5 release.
'test-rhino': {
'command': 'echo "Testing in Rhino..."; rhino -opt -1 "tests.js"',
'options': {
'execOptions': {
'cwd': 'tests'
}
}
},
'test-ringo': {
'command': 'echo "Testing in Ringo..."; ringo -o -1 "tests/tests.js"'
},
'test-node': {
'command': 'echo "Testing in Node..."; node "tests/tests.js"'
},
'test-browser': {
'command': 'echo "Testing in a browser..."; open "tests/index.html"'
}
}
});

grunt.loadNpmTasks('grunt-shell');

grunt.registerTask('cover', 'shell:cover');
grunt.registerTask('ci', [
'shell:test-narwhal',
'shell:test-phantomjs',
'shell:test-rhino',
'shell:test-ringo',
'shell:test-node',
]);
grunt.registerTask('test', [
'ci',
'shell:test-browser'
]);

grunt.registerTask('default', [
'shell:test-node'
]);

};
20 changes: 20 additions & 0 deletions LICENSE-MIT.txt
@@ -0,0 +1,20 @@
Copyright Mathias Bynens <http://mathiasbynens.be/>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
188 changes: 188 additions & 0 deletions README.md
@@ -0,0 +1,188 @@
# bacon-cipher [![Build status](https://travis-ci.org/mathiasbynens/bacon-cipher.svg?branch=master)](https://travis-ci.org/mathiasbynens/bacon-cipher) [![Dependency status](https://gemnasium.com/mathiasbynens/bacon-cipher.svg)](https://gemnasium.com/mathiasbynens/bacon-cipher)

_bacon-cipher_ is a JavaScript implementation of [Bacon’s cipher, a.k.a. the Baconian cipher](http://en.wikipedia.org/wiki/Bacon's_cipher). It can be used to encode plaintext to Bacon-ciphertext, or the other way around (i.e. decoding).

By default it uses the most common Bacon cipher alphabet, i.e. `ABCDEFGHIKLMNOPQRSTUWXYZ` (24 letters). This boils down to the following translations:

```
a AAAAA g AABBA n ABBAA t BAABA
b AAAAB h AABBB o ABBAB u-v BAABB
c AAABA i-j ABAAA p ABBBA w BABAA
d AAABB k ABAAB q ABBBB x BABAB
e AABAA l ABABA r BAAAA y BABBA
f AABAB m ABABB s BAAAB z BABBB
```

## Installation

Via [npm](http://npmjs.org/):

```bash
npm install bacon-cipher
```

Via [Bower](http://bower.io/):

```bash
bower install bacon-cipher
```

Via [Component](https://github.com/component/component):

```bash
component install mathiasbynens/bacon-cipher
```

In a browser:

```html
<script src="bacon.js"></script>
```

In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS](http://ringojs.org/):

```js
var bacon = require('bacon-cipher');
```

In [Rhino](http://www.mozilla.org/rhino/):

```js
load('bacon.js');
```

Using an AMD loader like [RequireJS](http://requirejs.org/):

```js
require(
{
'paths': {
'bacon': 'path/to/bacon'
}
},
['bacon'],
function(bacon) {
console.log(bacon);
}
);
```

## API

### `bacon.version`

A string representing the semantic version number.

### `bacon.encode(text, options)`

This function takes a string of text (the `text` parameter) and encrypts it using Bacon’s cipher.

```js
bacon.encode('steganography');
// → 'BAAABBAABAAABAAAABBAAAAAAABBAAABBABAABBABAAAAAAAAAABBBAAABBBBABBA'
```

By default it uses the most common Bacon cipher alphabet, i.e. `ABCDEFGHIKLMNOPQRSTUWXYZ` (24 letters). In this case instances of `J` are replaced with `I`, and instances of `V` are replaced with `U` before further encoding the input string.

```js
bacon.encode('James Vendetta');
// → 'ABAAAAAAAAABABBAABAABAAAB BAABBAABAAABBAAAAABBAABAABAABABAABAAAAAA'
```

It’s possible to pass an (optional) `options` object with an `alphabet` property to override the cipher alphabet. Note that in that case, no preprocessing (like replacing `j` and `v`) is done. For example, to use the full 26-letter alphabet:

```js
bacon.encode('James Vendetta', {
'alphabet': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
});
// → 'ABAABAAAAAABBAAAABAABAABA BABABAABAAABBABAAABBAABAABAABBBAABBAAAAA'
```

### `bacon.decode(text, options)`

This function takes a string of text (the `text` parameter) and decrypts it using Bacon’s cipher.

By default it uses the most common Bacon cipher alphabet, i.e. `ABCDEFGHIKLMNOPQRSTUWXYZ` (24 letters).

```js
bacon.decode('BAAABBAABAAABAAAABBAAAAAAABBAAABBABAABBABAAAAAAAAAABBBAAABBBBABBA');
// → 'STEGANOGRAPHY'

bacon.decode('ABAAAAAAAAABABBAABAABAAAB BAABBAABAAABBAAAAABBAABAABAABABAABAAAAAA');
// → 'IAMES UENDETTA'
```

It’s possible to pass an (optional) `options` object with an `alphabet` property to override the cipher alphabet. For example, to use the full 26-letter alphabet:

```js
bacon.decode('ABAABAAAAAABBAAAABAABAABA BABABAABAAABBABAAABBAABAABAABBBAABBAAAAA', {
'alphabet': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
});
// → 'JAMES VENDETTA'
```

### Using the `bacon` binary

To use the `bacon` binary in your shell, simply install _bacon-cipher_ globally using npm:

```bash
npm install -g bacon-cipher
```

After that you will be able to use Bacon’s cipher from the command line:

```bash
$ bacon --encode 'foo bar baz'
AABABABBABABBAB AAAABAAAAABAAAA AAAABAAAAABABBB

$ bacon --decode 'AABABABBABABBAB AAAABAAAAABAAAA AAAABAAAAABABBB'
FOO BAR BAZ

$ bacon --encode --alphabet=ABCDEFGHIJKLMNOPQRSTUVWXYZ 'Julius Caesar'
ABAABBABAAABABBABAAABABAABAABA AAABAAAAAAAABAABAABAAAAAABAAAB

$ bacon --decode --alphabet=ABCDEFGHIJKLMNOPQRSTUVWXYZ 'ABAABBABAAABABBABAAABABAABAABA AAABAAAAAAAABAABAABAAAAAABAAAB'
JULIUS CAESAR
```

Read a local text file, encrypt it using Bacon’s cipher with a non-default cipher alphabet, and save the result to a new file:

```bash
$ bacon --encode < foo.txt > foo-bacon.txt
```

Or do the same with an online text file:

```bash
$ curl -sL 'http://mths.be/brh' | bacon --encode > bacon.txt
```

Or, the opposite — read a local file containing Bacon ciphertext, decode it back to plain text, and save the result to a new file:

```bash
$ bacon --decode < bacon.txt > original.txt
```

See `bacon --help` for the full list of options.

## Support

_bacon_ is designed to work in at least Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, Rhino 1.7RC4, as well as old and modern versions of Chrome, Firefox, Safari, Opera, and Internet Explorer.

## Unit tests & code coverage

After cloning this repository, run `npm install` to install the dependencies needed for development and testing. You may want to install Istanbul _globally_ using `npm install istanbul -g`.

Once that’s done, you can run the unit tests in Node using `npm test` or `node tests/tests.js`. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use `grunt test`.

To generate the code coverage report, use `grunt cover`.

## Author

| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|---|
| [Mathias Bynens](http://mathiasbynens.be/) |

## License

_bacon_ is available under the [MIT](http://mths.be/mit) license.

0 comments on commit a1ecb26

Please sign in to comment.