update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -1,3 +1,3 @@
|
|||
'''SHA-256''' is the recommended stronger alternative to [[SHA-1]].
|
||||
'''[[wp:SHA-256|SHA-256]]''' is the recommended stronger alternative to [[SHA-1]].
|
||||
|
||||
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
>>> import hashlib
|
||||
>>> hashlib.sha256( "Rosetta code" ).hexdigest()
|
||||
>>> hashlib.sha256( "Rosetta code".encode() ).hexdigest()
|
||||
'764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf'
|
||||
>>>
|
||||
|
|
|
|||
20
Task/SHA-256/Racket/sha-256.rkt
Normal file
20
Task/SHA-256/Racket/sha-256.rkt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#lang racket/base
|
||||
|
||||
;; define a quick SH256 FFI interface, similar to the Racket's default
|
||||
;; SHA1 interface
|
||||
(require ffi/unsafe ffi/unsafe/define openssl/libcrypto
|
||||
(only-in openssl/sha1 bytes->hex-string))
|
||||
(define-ffi-definer defcrypto libcrypto)
|
||||
(defcrypto SHA256_Init (_fun _pointer -> _int))
|
||||
(defcrypto SHA256_Update (_fun _pointer _pointer _long -> _int))
|
||||
(defcrypto SHA256_Final (_fun _pointer _pointer -> _int))
|
||||
(define (sha256 bytes)
|
||||
(define ctx (malloc 128))
|
||||
(define result (make-bytes 32))
|
||||
(SHA256_Init ctx)
|
||||
(SHA256_Update ctx bytes (bytes-length bytes))
|
||||
(SHA256_Final result ctx)
|
||||
(bytes->hex-string result))
|
||||
|
||||
;; use the defined wrapper to solve the task
|
||||
(displayln (sha256 #"Rosetta code"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue