|
| 1 | +# encoding: ASCII-8BIT |
| 2 | + |
1 | 3 | ## |
2 | 4 | # Demo.rb |
3 | 5 | # Created: February 10, 2013 |
|
7 | 9 | ## |
8 | 10 | # |
9 | 11 | require 'httparty' |
10 | | -require './poracle' |
11 | | - |
12 | | -class DemoModule |
13 | | - attr_reader :iv, :data, :blocksize |
14 | | - |
15 | | - NAME = "DemoModule(tm)" |
16 | | - |
17 | | - # This function should load @data, @iv, and @blocksize appropriately |
18 | | - def initialize() |
19 | | - @data = HTTParty.get("http://localhost:20222/encrypt").parsed_response |
20 | | - # Parse 'data' here |
21 | | - @data = [@data].pack("H*") |
22 | | - @iv = nil |
23 | | - @blocksize = 16 |
24 | | - end |
25 | | - |
26 | | - # This should make a decryption attempt and return true/false |
27 | | - def attempt_decrypt(data) |
28 | | - result = HTTParty.get("http://localhost:20222/decrypt/#{data.unpack("H*").pop}").parsed_response |
29 | | - |
30 | | - # Match 'result' appropriately |
31 | | - return result !~ /Fail/ |
32 | | - end |
33 | | - |
34 | | - # Optionally define a character set, with the most common characters first |
35 | | - def character_set() |
36 | | - return ' eationsrlhdcumpfgybw.k:v-/,CT0SA;B#G2xI1PFWE)3(*M\'!LRDHN_"9UO54Vj87q$K6zJY%?Z+=@QX&|[]<>^{}'.chars.to_a |
37 | | - end |
38 | | -end |
| 12 | +require './Poracle' |
| 13 | + |
| 14 | +BLOCKSIZE = 16 |
39 | 15 |
|
40 | | -mod = DemoModule.new |
41 | | -puts "DECRYPTED: #{Poracle.decrypt(mod, mod.data, mod.iv, true)}" |
| 16 | +poracle = Poracle.new(BLOCKSIZE, true) do |data| |
| 17 | + url = "http://localhost:20222/decrypt/#{data.unpack('H*').pop()}" |
| 18 | + result = HTTParty.get(url) |
| 19 | + |
| 20 | + # Return |
| 21 | + result.parsed_response !~ /Fail/ |
| 22 | +end |
42 | 23 |
|
| 24 | +data = HTTParty.get("http://localhost:20222/encrypt").parsed_response |
| 25 | +print "Trying to decrypt: %s" % data |
| 26 | + |
| 27 | +result = poracle.decrypt([data].pack('H*')) |
| 28 | +puts("-----------------------------") |
| 29 | +puts("Decryption result") |
| 30 | +puts("-----------------------------") |
| 31 | +puts result |
| 32 | +puts("-----------------------------") |
| 33 | +puts() |
| 34 | + |
| 35 | +data = "The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents." |
| 36 | +print "Trying to encrypt: %s" % data |
| 37 | +result = poracle.encrypt(data) |
| 38 | + |
| 39 | +puts("-----------------------------") |
| 40 | +puts("Encrypted string") |
| 41 | +puts("-----------------------------") |
| 42 | +puts result.unpack('H*') |
| 43 | +puts("-----------------------------") |
| 44 | +puts() |
0 commit comments