Skip to content

feat: Added MD5 hashing algorithm #1519

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

Merged
merged 16 commits into from
Oct 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
ManpreetXSingh committed Oct 28, 2023
commit 4a6ff6955a65f6a382602593055a73d3913fb6a2
37 changes: 37 additions & 0 deletions Hashes/tests/MD5.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { MD5 } from '../MD5'

describe('Testing MD5 function', () => {
it('should return the correct hash for "The quick brown fox jumps over the lazy dog"', () => {
const input = new TextEncoder().encode(
'The quick brown fox jumps over the lazy dog'
)

const hash = Array.from(MD5(input), (byte) =>
byte.toString(16).padStart(2, '0')
).join('')

expect(hash).toBe('9e107d9d372bb6826bd81d3542a419d6')
})

it('should return the correct hash for "The quick brown fox jumps over the lazy dog."', () => {
const input = new TextEncoder().encode(
'The quick brown fox jumps over the lazy dog.'
)

const hash = Array.from(MD5(input), (byte) =>
byte.toString(16).padStart(2, '0')
).join('')

expect(hash).toBe('e4d909c290d0fb1ca068ffaddf22cbd0')
})

it('should correctly hash an empty string', () => {
const input = new TextEncoder().encode('')

const hash = Array.from(MD5(input), (byte) =>
byte.toString(16).padStart(2, '0')
).join('')

expect(hash).toBe('d41d8cd98f00b204e9800998ecf8427e')
})
})