```{index} single: algorithm; Digest::SHA function ``` ```{index} single: Digest::SHA::algorithm; Perl function ``` # algorithm Return the algorithm code of a `Digest::SHA` object. The code is the same integer you can pass to `new`: `1`, `224`, `256`, `384`, `512`, `512224`, or `512256`. Useful when a function receives a `Digest::SHA` object from elsewhere and needs to act differently based on which variant it is. ## Synopsis ```perl my $code = $sha->algorithm; ``` ## What you get back An integer in the set `{1, 224, 256, 384, 512, 512224, 512256}`. ## Examples ```perl my $sha = Digest::SHA->new("SHA-256"); print $sha->algorithm; # 256 ``` ```perl my $sha = Digest::SHA->new("SHA-512/224"); print $sha->algorithm; # 512224 ``` ```perl ## Dispatch on algorithm: my $code = $sha->algorithm; my $name = $code == 1 ? "SHA-1" : "SHA-$code"; ``` ## Edge cases - Called on a non-`Digest::SHA` object, returns `undef`. ## Differences from upstream Fully compatible with upstream `Digest::SHA` {{ upstream.Digest_SHA }}. ## See also - `hashsize` — digest length in bits for this algorithm. - `new` — accepts the values returned here as its algorithm argument.