How to resolve the algorithm SHA-256 step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm SHA-256 step by step in the Racket programming language
Table of Contents
Problem Statement
SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details. 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
Let's start with the solution:
Step by Step solution about How to resolve the algorithm SHA-256 step by step in the Racket programming language
Source code in the racket programming language
#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"))
You may also check:How to resolve the algorithm Sum of squares step by step in the Swift programming language
You may also check:How to resolve the algorithm Input loop step by step in the Ada programming language
You may also check:How to resolve the algorithm Call a function step by step in the Ruby programming language
You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the REXX programming language
You may also check:How to resolve the algorithm Unicode variable names step by step in the Common Lisp programming language