Skip to content

Instantly share code, notes, and snippets.

@mclosson
Created April 22, 2014 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mclosson/11166155 to your computer and use it in GitHub Desktop.
Save mclosson/11166155 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
class Bitlib
# Add Implementation Here
end
class Encryptor
# Add Implementation Here
end
class BitlibTest < MiniTest::Unit::TestCase
def test_converts_string_to_array_of_bits
bits = [0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0]
assert_equal bits, Bitlib.bits_for('god')
end
def test_converts_bits_array_to_string
bits = [0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0]
assert_equal 'god', Bitlib.string_for(bits)
end
def test_xor_two_equal_size_arrays
bits1 = [0, 1, 1, 0]
bits2 = [1, 1, 1, 1]
assert_equal [1, 0, 0, 1], Bitlib.xor(bits1, bits2)
end
end
class EncryptorTest < MiniTest::Unit::TestCase
def test_encrypt_xors_equal_length_plaintext_and_key
key = 'AX894DJC8FJKCV'
plaintext = 'This is a test'
ciphertext = "\x150QJ\x14-9cYf>.0\""
encryptor = Encryptor.new
assert_equal ciphertext, encryptor.encrypt(plaintext, key)
end
def test_encrypt_twice_with_same_key_decrypts
key = 'AX894DJC8FJKCV'
plaintext = 'This is a test'
ciphertext = "\x150QJ\x14-9cYf>.0\""
encryptor = Encryptor.new
assert_equal plaintext, encryptor.encrypt(encryptor.encrypt(plaintext, key), key)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment