-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathinitial.rb
138 lines (124 loc) · 3.44 KB
/
initial.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require_relative "sha256lib.rb"
# -------------------
# Initial Hash Values - H0
# -------------------
# The first thirty-two bits of the fractional parts of the square roots of the first eight prime numbers.
#
# Why?
# * These initial values don't _need_ to be anything in particular.
# * These are random-looking, irrational, and relatively independent from each other.
# * Using publicly-available numbers means that the initial hash values are less likely to have been chosen to allow for a backdoor.
# H0 = 6a09e667
# H1 = bb67ae85
# H2 = 3c6ef372
# H3 = a54ff53a
# H4 = 510e527f
# H5 = 9b05688c
# H6 = 1f83d9ab
# H7 = 5be0cd19
primes = [2, 3, 5, 7, 11, 13, 17, 19]
# --------
# Settings
# --------
indent = " " * 2
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression:"
puts "#{indent}-----------"
registers = ("a".."h").to_a
8.times do |i|
puts "#{indent}#{registers[i]} ="
end
delay(:slow)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} ="
end
delay(:slow)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0) (initial hash value)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} ="
end
delay(:slowest)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0) (initial hash value)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} = √#{primes[i]}"
end
delay(:slowest)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0) (initial hash value)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} = #{Math.sqrt(primes[i]).round(10)}"
end
delay(:slow)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0) (initial hash value)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} = #{(Math.sqrt(primes[i]) - Math.sqrt(primes[i]).floor).round(10)}"
end
delay(:slow)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0) (initial hash value)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} = #{(Math.sqrt(primes[i]) - Math.sqrt(primes[i]).floor).round(10)} * 2^32"
end
delay(:slow)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0) (initial hash value)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} = #{((Math.sqrt(primes[i]) - Math.sqrt(primes[i]).floor) * 2 ** 32).floor}"
end
delay(:slow)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0) (initial hash value)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} = #{bits(((Math.sqrt(primes[i]) - Math.sqrt(primes[i]).floor) * 2 ** 32).floor)}"
end
delay(:slow)
# Frame
system "clear"
puts $state + "\n" if defined? $state
puts "#{indent}-----------"
puts "#{indent}compression: (H0)"
puts "#{indent}-----------"
8.times do |i|
puts "#{indent}#{registers[i]} = #{bits(((Math.sqrt(primes[i]) - Math.sqrt(primes[i]).floor) * 2 ** 32).floor)}"
end
delay(:end)