Giter VIP home page Giter VIP logo

cryptographer's Introduction

Cryptographer

Challenge

Write a program which can encrypt messages. Write a second program which can decrypt those messages.

Restrictions

Don't use Ruby's tr method.

Algorithm

The simplest two-way encryption algorithm is called ROT-13. It's a good choice to build up your solution.

Template

Non-Object Based

If you're just getting started with Ruby and aren't familiar with creating classes and objects, create an encrypt.rb like this:

key = 13

message = "This is my secret"

# do your encryption here

puts encrypted_message

Then a decrypt.rb like:

key = 13

encrypted_message = "Guvf vf zl frperg"

# do your decryption here

puts message

Object-Based

If you're comfortable with creating classes, start with this:

class Encryptor
  # Your code here
end

class Decryptor
  # Your code here
end

class EncryptionEngine
  # Your code here
end

Which gets used like this:

engine = EncryptionEngine.new
output = engine.encrypt("My Message")
puts output  # outputs "Zl Zrffntr"
output2 = engine.decrypt("Zl Zrffntr")
puts output2 # outputs "My Message"

And of course you'll be using TDD. Maybe you start with:

require 'minitest/autorun'

class EncryptionEngineTest < Minitest::Test
  def test_it_encrypts_using_rot13
    engine = EncryptionEngine.new
    output = engine.encrypt("My Message")
    assert_equal "Zl Zrffntr", output
  end
end

Extensions

Flexible Rotation

When you finish ROT-13, add the ability to specify the rotation number when encrypting or decrypting. So a user could, for example, choose to use ROT-6.

Shuffled Cipher

The next level up would be to create a shuffled cipher (the pattern used for encrypting/decrypting). Create your own cipher which maps each letter to an arbitrary other letter (like a mapping to x and b mapping to j). And create a reversed version for decrypting.

cryptographer's People

Contributors

bu7ch avatar fabienalbi avatar mathisdetourbet avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.