Module: ToyOre::Scheme
- Defined in:
- lib/toy_ore/scheme.rb
Defined Under Namespace
Classes: LeftCiphertext, OreCiphertext, OreScheme, RightCiphertext
Class Method Summary collapse
-
.compare_ciphertexts(left_ciphertext, right_ciphertext) ⇒ Object
eg [1] pry(ToyOre::Scheme)> iv => 416 [2] pry(ToyOre::Scheme)> key => 208 [3] pry(ToyOre::Scheme)> iv ^ key => 368 [4] pry(ToyOre::Scheme)> (iv ^ key) ^ cmp_result => -369 [5] pry(ToyOre::Scheme)> (iv ^ key) ^ -369 => -1.
-
.compare_plaintexts(a, b) ⇒ Object
Compares 2 plaintexts and returns a cmp_result.
-
.encrypt(iv, key, cmp_result) ⇒ Integer
Encrypts a comparison result by XOR’ing the iv and key.
Class Method Details
.compare_ciphertexts(left_ciphertext, right_ciphertext) ⇒ Object
eg
- 1
-
pry(ToyOre::Scheme)> iv
> 416
- 2
-
pry(ToyOre::Scheme)> key
> 208
- 3
-
pry(ToyOre::Scheme)> iv ^ key
> 368
- 4
-
pry(ToyOre::Scheme)> (iv ^ key) ^ cmp_result
> -369
- 5
-
pry(ToyOre::Scheme)> (iv ^ key) ^ -369
> -1
75 76 77 |
# File 'lib/toy_ore/scheme.rb', line 75 def self.compare_ciphertexts(left_ciphertext, right_ciphertext) (right_ciphertext.iv ^ left_ciphertext.key) ^ right_ciphertext.encryptions[left_ciphertext.offset] end |
.compare_plaintexts(a, b) ⇒ Object
Compares 2 plaintexts and returns a cmp_result. If a < b = -1 If a == b = 0 if a > b = 1
32 33 34 35 36 37 38 39 40 |
# File 'lib/toy_ore/scheme.rb', line 32 def self.compare_plaintexts(a, b) if a < b return -1 elsif a == b return 0 else return 1 end end |
.encrypt(iv, key, cmp_result) ⇒ Integer
Encrypts a comparison result by XOR’ing the iv and key. Then XORing that result with the comparaison result.
Uses an IV for non-determinism.
A Boolean logic operation that compares two input bits and generates one output bit. If the bits are the same, the result is 0. If the bits are different, the result is 1. ^ represents the xor operator
18 19 20 |
# File 'lib/toy_ore/scheme.rb', line 18 def self.encrypt(iv, key, cmp_result) (iv ^ key) ^ cmp_result end |