sha265.rb
# -------
# SHA-256 - Complete SHA-256 function
# -------
SHA-256 - Complete SHA-256 function
SHA - 256 - Complete SHA - 256 function
def sha256(string)
  message = bitstring(string)
  padded = padding(message)
  blocks = split(padded, 512)
  ---
  hash = IV
  blocks.each do |block|
    schedule = calculate_schedule(block)
    initial = hash.clone
    hash = compression(initial, schedule, constants = K)
  end
  return hash.map { |w| w.to_s(16).rjust(8, '0') }.join
end
def sha256 ( string ) message = bitstring ( string ) padded = padding ( message ) blocks = split ( padded , 512 ) hash = IV blocks . each do | block | schedule = calculate_schedule ( block ) initial = hash . clone hash = compression ( initial , schedule , constants = K ) end return hash . map { | w | w . to_s ( 16 ) . rjust ( 8 , '0' ) } . join end
SHA-256 - Complete SHA-256 function
SHA - 256 - Complete SHA - 256 function
# 0. Convert String to Binary # --------------------------- # 1. Preprocessing # ---------------- # Pad message # Split up in to 512 bit message blocks # 2. Hash Computation # ------------------- # Set initial hash state using initial hash values # For each message block # Prepare 64 word message schedule # Remember starting hash values # Apply compression function to update hash values # 3. Result # --------- # Convert hash values to hexadecimal and concatenate
string