# 3. Funzioni
Le operazioni di cui sopra possono essere combinate per creare funzioni.
Le prime quattro funzioni sono nominate usando il simbolo greco Sigma (minuscolo σ
e maiuscolo Σ
). Questo non è per una ragione particolare, è solo per poter dare dei nomi ad alcune operazioni combinate.
# σ0 (sigma0.rb
)
σ0(x) = ROTR^7(x) ^ ROTR^18(x) ^ SHR^3(x)
# σ1 (sigma1.rb
)
σ1(x) = ROTR^17(x) ^ ROTR^19(x) ^ SHR^10(x)
# Σ0 (usigma0.rb
)
Σ0(x) = ROTR^2(x) ^ ROTR^13(x) ^ ROTR^22(x)
# Σ1 (usigma1.rb
)
Σ1(x) = ROTR^6(x) ^ ROTR^11(x) ^ ROTR^25(x)
Le ultime due funzioni di Choice e Majority accettano tre input diversi.
# Choice (ch.rb
)
Questa funzione usa il bit x
per scegliere tra i bit y
e z
. Sceglie il bit y
se x=1
, e sceglie il bit z
se x=0
.
Ch(x, y, z) = (x & y) ^ (~x & z)
# Majority (maj.rb
)
Questa funzione restituisce la maggioranza dei tre bit.
Maj(x, y, z) = (x & y) ^ (x & z) ^ (y & z)