Ad
Swift SHA1 Function Without HMAC
i try to get SHA1 working in swift. without using CommonCrypto since it is not default in swift.
please see https://gist.github.com/wdg/f7c8c4088030c59f0f45 (since it's a little to big to post)
if i run a test case in Xcode:
func test_sha1() {
XCTAssertEqual(sha1("test"), "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")
}
it will fail, and return 2d891cc96e32c32e8d26704d101208b954f435a5
i got the hash with:
$ php -r "echo sha1('test');echo(PHP_EOL);"
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
i think the problem is that in the javascript file they use >>>
and i don't know what this operator is.
So i have used >>
.
i hope someone can help.
Thanks in advance
Ad
Answer
I've got a solution, there was something wrong with the rotate function.
i have changed the rotate function to
func rotate(n: Int, _ s: Int) -> Int {
return ((n << s) & 0xFFFFFFFF) | (n >> (32 - s))
}
and now it works.
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad