Jordanthedud
Jordanthedud

Reputation: 61

Hashing in PHP. How does SHA-256 work?

I'm very new to PHP and i was looking at some Provability Fair code that dealt with hashing. I was wondering what exactly is going on when the values are being hashed. I know that its converting it to hexits, but how exactly is it doing it. Also what is "-" doing exactly? Here is the code i was looking at to give everyone a better idea. Thanks in advance!

$server_seed = "39b7d32fcb743c244c569a56d6de4dc27577d6277d6cf155bdcba6d05befcb34";
$lotto = "0422262831";
$round_id = "1";
$hash = hash("sha256",$server_seed."-".$lotto."-".$round_id);
$roll = hexdec(substr($hash,0,8)) % 15;
echo "Round $round_id = $roll";

Upvotes: 2

Views: 11792

Answers (1)

Rajesh Patel
Rajesh Patel

Reputation: 2036

SHA-256 is a 256 bit (32 bytes) hashing algorithm which can calculate hash code for an input up to 264-1 bits. It undergoes 64 rounds off hashing. The calculated hash code will be a 64 digit hexadecimal number. For example, the SHA-256 hash code for rajeshpatel is 5662895e0af2b7b9c23c753b44b3628299a009949000e6cfd60fd16c02c00433

PHP has hash() function to calculate SHA-256 hash code.

<?php
echo hash('sha256', 'www.MyTecBits.com');
?>

Upvotes: 6

Related Questions