Skip to content

Instantly share code, notes, and snippets.

@d34th4ck3r
Last active December 26, 2016 12:12
Show Gist options
  • Save d34th4ck3r/567c5a9e28c12dcfc1d732aff1092f24 to your computer and use it in GitHub Desktop.
Save d34th4ck3r/567c5a9e28c12dcfc1d732aff1092f24 to your computer and use it in GitHub Desktop.
require "base32"
require "rotp"
require "base64"
require "uri"
require 'net/http'
require 'json'
enc = Base32.encode("gautam1237@gmail.comHDECHALLENGE003")
p enc.gsub! "=",""
totp = ROTP::TOTP.new(enc,:digest=>"sha512",:digits=>10)
p totp
p totp.now
uri = URI.parse('http://hdechallenge-solve.appspot.com/challenge/003/endpoint')
data = {'github_url'=> 'https://gist.github.com/d34th4ck3r/c08a4731da27e9d11675', 'contact_email'=> 'gautam1237@gmail.com'}
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-Type', 'application/json')
request.add_field('Content-Length', data.size)
request.add_field('Authorization', 'Basic '+Base64.strict_encode64("gautam1237@gmail.com:"+totp.now))
request.body = data.to_json
response = http.request(request)
p response.code
p response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment