forked from in3rsha/sha256-animation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.rb
63 lines (56 loc) · 1.32 KB
/
message.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
57
58
59
60
61
62
63
require_relative 'sha256lib.rb'
# -------
# Default
# -------
if !defined? $input
# default
$input = "abc"
$type = "string"
# argument passed
$input = ARGV[0] if ARGV[0] # only accept strings for now
# calculate message
$bytes = $input.bytes
$message = $input.bytes.map {|x| x.to_s(2).rjust(8, "0")}.join
end
# puts string.bytes.inspect # [97, 98, 99]
# puts string.bytes.map{|x| x.to_s(16)}.inspect # ["61", "62", "63"]
# puts string.bytes.map{|x| x.to_s(2)}.inspect # ["1100001", "1100010", "1100011"]
# puts string.unpack("B*") # 011000010110001001100011
# ---------
# Animation
# ---------
system "clear"
puts "-------"
puts "message:"
puts "-------"
delay(:fast)
system "clear"
puts "-------"
puts "message:"
puts "-------"
puts "input: #{$input} (#{$type})"
delay(:normal)
system "clear"
puts "-------"
puts "message:"
puts "-------"
puts "input: #{$input} (#{$type})"
puts "bytes: #{$bytes.inspect}" if defined? $bytes
delay(:normal)
system "clear"
puts "-------"
puts "message:"
puts "-------"
puts "input: #{$input} (#{$type})"
puts "bytes: #{$bytes.inspect}" if defined? $bytes
puts "message: #{$message}"
delay(:end)
# Save Final State
$state = <<-FRAME
-------
message:
-------
input: #{$input} (#{$type})
bytes: #{$bytes.inspect}
message: #{$message}
FRAME