-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat-Ruby: add crc32, sha1, and md5 function #54
Open
iqbaleff214
wants to merge
7
commits into
teknologi-umum:master
Choose a base branch
from
iqbaleff214:ruby/crypto
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
116b0f9
Feat-Ruby: add crc32 function
iqbaleff214 894425a
Feat-Ruby: add sha1 function
iqbaleff214 5032765
Feat-Ruby: add sha1_file function
iqbaleff214 1a31175
Feat-Ruby: add md5 function
iqbaleff214 e314624
Feat-Ruby: add md5_file function
iqbaleff214 42b5ab5
Merge branch 'master' into ruby/crypto
iqbaleff214 201c4f3
Merge branch 'master' into ruby/crypto
iqbaleff214 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "zlib" | ||
|
||
module Pehape | ||
def self.crc32(string) | ||
Zlib.crc32(string.to_s) | ||
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require "digest" | ||
|
||
module Pehape | ||
def self.md5(string, binary=nil) | ||
result = Digest::MD5.new << string.to_s | ||
binary ? result.digest : result.hexdigest | ||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require "digest" | ||
|
||
module Pehape | ||
def self.md5_file(filename, binary=nil) | ||
return false unless File.exist?(filename.to_s) | ||
|
||
result = Digest::MD5.file(filename.to_s) | ||
binary ? result.digest : result.hexdigest | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require "digest" | ||
|
||
module Pehape | ||
def self.sha1(string, binary=nil) | ||
result = Digest::SHA1.new << string.to_s | ||
binary ? result.digest : result.hexdigest | ||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require "digest" | ||
|
||
module Pehape | ||
def self.sha1_file(filename, binary=nil) | ||
return false unless File.exist?(filename.to_s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kalo di php emang dia return false kalo filenya ngga exist? |
||
|
||
result = Digest::SHA1.file(filename.to_s) | ||
binary ? result.digest : result.hexdigest | ||
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Pehape do | ||
describe "crc32" do | ||
it "returns the crc32 checksum of string as an integer." do | ||
expect(Pehape.crc32("Hello World!")).to eq(472_456_355) | ||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Pehape do | ||
describe "md5_file" do | ||
it "returns a string on success." do | ||
filename = File.expand_path("./README.md") | ||
expect(Pehape.md5_file(filename)).to eq("6cccfa61af5a5310f08f3fabcbe230ae") | ||
end | ||
|
||
it "returns false on fail." do | ||
filename = File.expand_path("./robot.txt") | ||
expect(Pehape.md5_file(filename)).to eq(false) | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Pehape do | ||
describe "md5" do | ||
it "returns the hash as a 32-character hexadecimal number." do | ||
expect(Pehape.md5("Hello World!")).to eq("ed076287532e86365e841e92bfc50d8c") | ||
expect(Pehape.md5("apple")).to eq("1f3870be274f6c49b3e31a0c6728957f") | ||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Pehape do | ||
describe "sha1_file" do | ||
it "returns file hash as a string on success." do | ||
filename = File.expand_path("./README.md") | ||
expect(Pehape.sha1_file(filename)).to eq("64285a71bb456bd05a5466ff7076bf2c377ecd57") | ||
end | ||
|
||
it "returns false on fail." do | ||
filename = File.expand_path("./robot.txt") | ||
expect(Pehape.sha1_file(filename)).to eq(false) | ||
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Pehape do | ||
describe "sha1" do | ||
it "returns the sha1 hash as a string." do | ||
expect(Pehape.sha1("Hello World!")).to eq("2ef7bde608ce5404e97d5f042f95f89f1c232871") | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kalo di php emang dia return false kalo file ngga exists?