Skip to content

Instantly share code, notes, and snippets.

@gitpraetorianlabs
Created February 21, 2017 17:13
Show Gist options
  • Save gitpraetorianlabs/581ce146b4dc371e46a1b5bca32482fc to your computer and use it in GitHub Desktop.
Save gitpraetorianlabs/581ce146b4dc371e46a1b5bca32482fc to your computer and use it in GitHub Desktop.
Ruby Starter code for the Crypto Challenge
require 'rest-client'
require 'json'
require 'pp'
class CryptoAPI
def initialize(email)
@base = 'http://crypto.praetorian.com'
@email = email
@token = self.token
end
def token
data = {'email' => @email}.to_json
ret = RestClient.post "#{@base}/api-token-auth/", data, :content_type => :json, :accept => :json
JSON.parse(ret)['token']
end
def fetch(n)
ret = RestClient.get "#{@base}/challenge/#{n}/", :content_type => :json, :accept => :json, :Authorization => "JWT #{@token}"
JSON.parse(ret)
end
def solve(n, guess)
data = {'guess' => guess}
ret = RestClient.post "#{@base}/challenge/#{n}/", data, :content_type => :json, :accept => :json, :Authorization => "JWT #{@token}"
JSON.parse(ret)
end
def status
ret = RestClient.get "#{@base}/hash/", :content_type => :json, :accept => :json, :Authorization => "JWT #{@token}"
JSON.parse(ret)
end
end
# Class values
# Declare Class
crypto = CryptoAPI.new('EMAIL@EMAIL.COM')
# Fetch level 0
level = 0
data = crypto.fetch(level)
# Level 0 is a freebie and gives you the password
guess = data['challenge']
h = crypto.solve(level, guess)
d = crypto.status
puts 'Praetorian Crypto Challenge'
puts " Level: #{d['level']}"
puts " Hash: #{d['hash']}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment