Skip to content
Permalink
Browse files

add cryptographic hashing functions (fixes #9)

  • Loading branch information...
nickbclifford committed Jan 31, 2018
1 parent 049b83d commit d61a62612f6df03ed1302535b7703315bc4840c1
Showing with 29 additions and 0 deletions.
  1. +4 −0 components.md
  2. +13 −0 lib/components.rb
  3. +12 −0 spec/extras_spec.rb
@@ -340,6 +340,10 @@ Because of input restrictions, complex numbers are represented as an array in th

|Component|Action|Description|
|---------|------|-----------|
|`·¹`|Pop `a`|Pushes the MD5 hash of `a`.|
|`·²`|Pop `a`|Pushes the SHA1 hash of `a`.|
|`·³`|Pop `a`|Pushes the SHA256 hash of `a`.|
|`·⁴`|Pop `a`|Pushes the SHA512 hash of `a`.|
|`·/`|Pop `a`, `b`|Pushes an array of the matched string + captures of `a` tested against regex `b`.|
|`·\`|Pop `a`|Pushes the diagonals of `a`, assuming `a` is a matrix.|
|`·G`|Pop `a`|Performs a GET request to `a` and pushes the response body.|
@@ -2,6 +2,7 @@

require 'bigdecimal/math'
require 'cmath'
require 'digest'
require 'gsl'
require 'net/http'
require 'prime'
@@ -1006,6 +1007,18 @@ class Ohm
# left single quote reserved: min by
# right single quote resereved: max by
'·' => {
'¹' => {
call: ->(a){Digest::MD5.hexdigest(untyped_to_s(a))}
},
'²' => {
call: ->(a){Digest::SHA1.hexdigest(untyped_to_s(a))}
},
'³' => {
call: ->(a){Digest::SHA256.hexdigest(untyped_to_s(a))}
},
'' => {
call: ->(a){Digest::SHA512.hexdigest(untyped_to_s(a))}
},
'/' => {
call: ->(a, b){untyped_to_s(a).match(untyped_to_s(b)).to_a}
},
@@ -1,5 +1,17 @@
RSpec.describe Ohm do
describe 'extra components' do
describe '·¹' do
include_examples 'component', 'the MD5 hash of a string', stack: %w(test), result: '098f6bcd4621d373cade4e832627b4f6'
end
describe '·²' do
include_examples 'component', 'the SHA1 hash of a string', stack: %w(test), result: 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'
end
describe '·³' do
include_examples 'component', 'the SHA256 hash of a string', stack: %w(test), result: '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
end
describe '·⁴' do
include_examples 'component', 'the SHA512 hash of a string', stack: %w(test), result: 'ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff'
end
describe '·/' do
include_examples 'component', 'the match and captures of a regex against a string', stack: %w(2016-04-20 (\d{4})-(\d{2})-(\d{2})), result: %w(2016-04-20 2016 04 20)
end

0 comments on commit d61a626

Please sign in to comment.
You can’t perform that action at this time.