├── .travis.yml ├── lib ├── missy_elliott │ └── version.rb └── missy_elliott.rb ├── spec ├── fixtures │ └── encode_example └── missy_elliott_spec.rb ├── Gemfile ├── Rakefile ├── Gemfile.lock ├── missy_elliott.gemspec ├── LICENSE.txt └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.1 4 | -------------------------------------------------------------------------------- /lib/missy_elliott/version.rb: -------------------------------------------------------------------------------- 1 | module MissyElliott 2 | VERSION = "1.0.0" 3 | end 4 | -------------------------------------------------------------------------------- /spec/fixtures/encode_example: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tom-lord/missy_elliott/HEAD/spec/fixtures/encode_example -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'minitest', group: [:development, :test] 4 | 5 | # Specify your gem's dependencies in missy_elliot.gemspec 6 | gemspec 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require 'rake/testtask' 3 | 4 | Rake::TestTask.new do |t| 5 | t.pattern = "spec/*_spec.rb" 6 | end 7 | 8 | task :default => :test 9 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | missy_elliott (1.0.0) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | minitest (5.5.1) 10 | rake (10.4.2) 11 | 12 | PLATFORMS 13 | ruby 14 | 15 | DEPENDENCIES 16 | bundler (~> 1.7) 17 | minitest 18 | missy_elliott! 19 | rake (~> 10.0) 20 | -------------------------------------------------------------------------------- /spec/missy_elliott_spec.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | require './lib/missy_elliott.rb' 3 | 4 | describe "MissyElliott" do 5 | it "Must be worth it" do 6 | original = "Is it worth it?" 7 | encoded = MissyElliott.encode(original) 8 | decoded = MissyElliott.decode(encoded) 9 | original.must_equal decoded 10 | end 11 | 12 | it "Tests be more explicit" do 13 | encoded = File.read './spec/fixtures/encode_example' 14 | decoded = MissyElliott.decode(encoded) 15 | decoded.must_equal "Is it really worth it?" 16 | end 17 | end 18 | 19 | -------------------------------------------------------------------------------- /lib/missy_elliott.rb: -------------------------------------------------------------------------------- 1 | module MissyElliott 2 | def self.encode(input) 3 | input.bytes.map do |byte| 4 | bits = byte.to_s(2).rjust(8, "0").split("") 5 | bits << bits.shift # Shift yo bits down 6 | flip_it(bits).reverse.join.to_i(2).chr # Flip it and reverse it 7 | end.join 8 | end 9 | 10 | def self.decode(input) 11 | input.bytes.map do |byte| 12 | bits = byte.to_s(2).rjust(8, "0").split("") 13 | bits = flip_it(bits.reverse) # Reverse it and flip it 14 | bits.unshift(bits.pop).join.to_i(2).chr # Shift yo bits up 15 | end.join 16 | end 17 | 18 | private 19 | def self.flip_it(bits) 20 | bits.map do |bit| 21 | bit == "1" ? "0" : "1" 22 | end 23 | end 24 | end 25 | 26 | -------------------------------------------------------------------------------- /missy_elliott.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'missy_elliott/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "missy_elliott" 8 | spec.version = MissyElliott::VERSION 9 | spec.authors = ["Tom Lord"] 10 | spec.email = ["tom.lord@gmail.com"] 11 | spec.summary = %q{Applies the Missy Elliott encryption algorithm on a string} 12 | spec.description = %q{Got a big string? Let me search it. Shift yo bits down, flip it and reverse it.} 13 | spec.homepage = "" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_development_dependency "bundler", "~> 1.7" 22 | spec.add_development_dependency "rake", "~> 10.0" 23 | end 24 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Tom Lord 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MissyElliott 2 | [![Gem Version](https://badge.fury.io/rb/missy_elliott.svg)](http://badge.fury.io/rb/missy_elliott) 3 | [![Build Status](https://travis-ci.org/tom-lord/missy_elliott.svg?branch=master)](https://travis-ci.org/tom-lord/missy_elliott/builds) 4 | 5 | [![Missy Elliott](http://i.imgur.com/P23jxLq.jpg)](https://www.youtube.com/watch?v=zm28EEeyLek) 6 | 7 | ```ruby 8 | MissyElliott.encode("Example") # => "\xAE\xF0\xBC\xA4\xF8\xE4\xAC" 9 | 10 | #"Example" 11 | #--> ["E", "x", "a", "m", "p", "l", "e"] 12 | #--> [69, 120, 97, 109, 112, 108, 101] 13 | #--> ["01000101", "01111000", "01100001", "01101101", "01110000", "01101100", "01100101"] 14 | # Shift yo bits down 15 | #--> ["10001010", "11110000", "11000010", "11011010", "11100000", "11011000", "11001010"] 16 | # Flip it 17 | #--> ["01110101", "00001111", "00111101", "00100101", "00011111", "00100111", "00110101"] 18 | # And reverse it 19 | #--> ["10101110", "11110000", "10111100", "10100100", "11111000", "11100100", "10101100"] 20 | #--> [174, 240, 188, 164, 248, 228, 172] 21 | #--> ["\xAE", "\xF0", "\xBC", "\xA4", "\xF8", "\xE4", "\xAC"] 22 | #--> "\xAE\xF0\xBC\xA4\xF8\xE4\xAC" 23 | 24 | MissyElliott.decode("\xAE\xF0\xBC\xA4\xF8\xE4\xAC") # => "Example" 25 | ``` 26 | 27 | Although `MissyElliott.encode` and `MissyElliott.decode` have different implentations, they are actually doing the exact same thing! 28 | 29 | This is because the algorithm is a reciprocal cipher. [See what I had to say about all this on my blog](http://tom-lord.weebly.com/blog/missy-elliotts-reciprocal-cipher-and-perfect-oscillating-sequences). 30 | 31 | This gem is a blatant rip-off of [an old XKCD comic](http://xkcd.com/153/): 32 | 33 | ![XKCD Comic](http://imgs.xkcd.com/comics/cryptography.png) 34 | 35 | ## Installation 36 | 37 | Add this line to your application's Gemfile: 38 | 39 | ```ruby 40 | gem 'missy_elliott' 41 | ``` 42 | 43 | And then execute: 44 | 45 | $ bundle 46 | 47 | Or install it yourself as: 48 | 49 | $ gem install missy_elliott 50 | 51 | ## Contributing 52 | 53 | 1. Got a bug fix? 54 | 2. You'd better work on it ( https://github.com/tom-lord/missy_elliott/fork ) 55 | 3. Create your feature branch (`git checkout -b my-new-feature`) 56 | 4. Commit it (`git commit -am 'Add some feature'`) 57 | 5. And converse it (`git push origin my-new-feature`) 58 | --------------------------------------------------------------------------------