-
Notifications
You must be signed in to change notification settings - Fork 163
/
blocks.rb
56 lines (49 loc) · 1.1 KB
/
blocks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require_relative "sha256lib.rb"
# -------
# Default
# -------
if !defined? $input
# default
$input = "abc"
$message = $input.unpack("B*")[0]
# argument passed
$message = ARGV[0] if ARGV[0] # accept binary message string
# calculate padded message
$padded = padding($message)
end
# --------------
# Message Blocks
# --------------
$blocks = split($padded, 512)
# ---------
# Animation
# ---------
system "clear"
puts $state + "\n" if defined? $state
puts "--------------"
puts "message blocks:"
puts "--------------"
delay(:normal)
system "clear"
puts $state + "\n" if defined? $state
puts "--------------"
puts "message blocks:"
puts "--------------"
$blocks.each.with_index do |block, i|
puts "#{i}: #{block}"
delay(:normal)
end
delay(:slow)
# Save Final State
contents = "" # contruct string with each block so we can use it inside the final frame
$blocks.each.with_index do |block, i|
contents << "#{i}: #{block}"
contents << "\n" if i < $blocks.size - 1 # do not add extra new line after last block
end
$state = <<-FRAME
#{$state}
--------------
message blocks:
--------------
#{contents}
FRAME