Skip to content

Commit

Permalink
hash224
Browse files Browse the repository at this point in the history
  • Loading branch information
imaman committed Nov 13, 2024
1 parent 6cc82b7 commit b765628
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions modules/septima-lang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,35 @@ Array.isArray('not array') // Returns false
Array.isArray({ key: 'val' }) // Returns false
```
# Septima: An Overview
[Previous sections remain unchanged...]
### Built-in Methods
[Previous built-in methods content remains unchanged...]
#### Cryptographic Hashing
Septima provides a secure hashing function through the `crypto.hash224()` method, which computes SHA-224 hashes of any value. The method takes a single argument of any type and returns a hexadecimal string representing the hash.
```javascript
// Hash a simple string
crypto.hash224('hello') // Returns a 56-character hex string

// Hash numbers
crypto.hash224(42) // Hashes the number 42

// Hash complex objects
crypto.hash224({ name: 'Alice', roles: ['admin', 'user'], settings: { theme: 'dark' } }) // Hashes the entire object structure

// Hashes are deterministic but unique per input
crypto.hash224('A') === crypto.hash224('A') // true (same input = same hash)
crypto.hash224('A') !== crypto.hash224('B') // true (different input = different hash)
```
Note: Septima's `crypto` object is not intended to be compatible with Node.js's `crypto` module. It provides its own simplified cryptographic utilities specifically designed for Septima's use cases.
### Console Output for Debugging
Like JavaScript, Septima provides `console.log()` for debugging and monitoring your code. However, unlike JavaScript's `console.log()` which can take multiple arguments, Septima's version accepts only a single argument. In keeping with Septima's functional nature, `console.log()` returns its argument, making it useful within expressions.
Expand Down
2 changes: 1 addition & 1 deletion modules/septima-lang/tests/septima.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ describe('septima', () => {
expect(run(`JSON.parse(5000)`)).toEqual(5000)
})
})
describe('hash', () => {
describe('hash224', () => {
const hashOf = (u: unknown) => crypto.createHash('sha224').update(JSON.stringify(u)).digest('hex')
test('can compute hash values of strings', () => {
expect(run(`crypto.hash224('A')`)).toEqual(hashOf('A'))
Expand Down

0 comments on commit b765628

Please sign in to comment.