-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix references to Crystal's Int class - Fix links to Crystal docs (no longer linking to a specific version) - Update the test to match instructions
- Loading branch information
Showing
7 changed files
with
30 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
[ | ||
{ | ||
"url": "https://crystal-lang.org/reference/1.10/syntax_and_semantics/operators.html#binary", | ||
"url": "https://crystal-lang.org/reference/syntax_and_semantics/operators.html#binary", | ||
"description": "Crystal docs: List of operators - Binary" | ||
}, | ||
{ | ||
"url": "https://crystal-lang.org/reference/1.10/syntax_and_semantics/operators.html#shifts", | ||
"url": "https://crystal-lang.org/reference/syntax_and_semantics/operators.html#shifts", | ||
"description": "Crystal docs: List of operators - Shifts" | ||
}, | ||
{ | ||
"url": "https://crystal-lang.org/reference/1.10/syntax_and_semantics/operators.html#other-unary-operators", | ||
"url": "https://crystal-lang.org/reference/syntax_and_semantics/operators.html#other-unary-operators", | ||
"description": "Crystal docs: List of operators - Unary" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
module Secrets | ||
def shift_back(value : UInt8, numberOfPlaces : UInt8) : UInt8 | ||
def self.shift_back(value : UInt8, numberOfPlaces : UInt8) : UInt8 | ||
value << numberOfPlaces | ||
end | ||
|
||
def apply_mask(value : UInt8, mask : UInt8) : UInt8 | ||
def self.apply_mask(value : UInt8, mask : UInt8) : UInt8 | ||
value & mask | ||
end | ||
|
||
def set_bits(value1 : UInt8, value2 : UInt8) : UInt8 | ||
def self.set_bits(value1 : UInt8, value2 : UInt8) : UInt8 | ||
value1 | value2 | ||
end | ||
|
||
def reverse_xor(value : UInt8, agreedValue : UInt8) : UInt8 | ||
def self.reverse_xor(value : UInt8, agreedValue : UInt8) : UInt8 | ||
value ^ ~agreedValue | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,64 @@ | ||
require "spec" | ||
require "../src/*" | ||
|
||
include Secrets | ||
|
||
describe "Secrets" do | ||
describe "shift_back" do | ||
it "should be able to shift 0 places" do | ||
shift_back(15, 0).should eq 15 | ||
Secrets.shift_back(15, 0).should eq 15 | ||
end | ||
|
||
it "should be able to shift 1 place to the left" do | ||
shift_back(7, 1).should eq 14 | ||
Secrets.shift_back(7, 1).should eq 14 | ||
end | ||
|
||
it "should be able to shift 4 places to the left" do | ||
shift_back(5, 4).should eq 80 | ||
Secrets.shift_back(5, 4).should eq 80 | ||
end | ||
|
||
it "should be able to shift bits off" do | ||
shift_back(96, 4).should eq 0 | ||
Secrets.shift_back(96, 4).should eq 0 | ||
end | ||
end | ||
|
||
describe "apply_mask" do | ||
it "should be able to AND value with mask bits all 1" do | ||
apply_mask(101, 255).should eq 101 | ||
Secrets.apply_mask(101, 255).should eq 101 | ||
end | ||
|
||
it "should be able to AND value with mask bits all 0" do | ||
apply_mask(101, 0).should eq 0 | ||
Secrets.apply_mask(101, 0).should eq 0 | ||
end | ||
|
||
it "should be able to AND value with some bits 1" do | ||
apply_mask(62, 85).should eq 20 | ||
Secrets.apply_mask(62, 85).should eq 20 | ||
end | ||
end | ||
|
||
describe "set_bits" do | ||
it "should be able to OR value with 0s" do | ||
set_bits(107, 0).should eq 107 | ||
Secrets.set_bits(107, 0).should eq 107 | ||
end | ||
|
||
it "should be able to OR with with 1s" do | ||
set_bits(107, 255).should eq 255 | ||
Secrets.set_bits(107, 255).should eq 255 | ||
end | ||
|
||
it "should be able to set some bits" do | ||
set_bits(62, 85).should eq 127 | ||
Secrets.set_bits(62, 85).should eq 127 | ||
end | ||
end | ||
|
||
describe "reverse_xor" do | ||
it "should be able to reverse with all 1s" do | ||
reverse_xor(106, 255).should eq 106 | ||
Secrets.reverse_xor(106, 255).should eq 106 | ||
end | ||
|
||
it "should be able to reverse with all 0s" do | ||
reverse_xor(106, 0).should eq 149 | ||
Secrets.reverse_xor(106, 0).should eq 149 | ||
end | ||
|
||
it "should be able to reverse with mix of 1s and 0s" do | ||
reverse_xor(62, 85).should eq 148 | ||
Secrets.reverse_xor(62, 85).should eq 148 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
module Secrets | ||
def shift_back(value : UInt8, numberOfPlaces : UInt8) : UInt8 | ||
def self.shift_back(value : UInt8, numberOfPlaces : UInt8) : UInt8 | ||
raise "Please implement the Secrets::shift_back method" | ||
end | ||
|
||
def apply_mask(value : UInt8, mask : UInt8) : UInt8 | ||
def self.apply_mask(value : UInt8, mask : UInt8) : UInt8 | ||
raise "Please implement the Secrets::apply_mask method" | ||
end | ||
|
||
def set_bits(value1 : UInt8, value2 : UInt8) : UInt8 | ||
def self.set_bits(value1 : UInt8, value2 : UInt8) : UInt8 | ||
raise "Please implement the Secrets::set_bits method" | ||
end | ||
|
||
def reverse_xor(value : UInt8, agreedValue : UInt8) : UInt8 | ||
def self.reverse_xor(value : UInt8, agreedValue : UInt8) : UInt8 | ||
raise "Please implement the Secrets::reverse_xor method" | ||
end | ||
end |