SHA-1: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(New post directly implementing the algorithm. In addition to an existing post which calls a built in language feature.) |
m (→{{header|Wren}}: Minor tidy) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1,175:
public:
std::string message_digest(const std::string& message) {
std::vector<
const std::vector<int8_t> bytes = add_padding(message);
for ( uint64_t i = 0; i < bytes.size() / BLOCK_LENGTH; ++i ) {
std::vector<
for ( uint32_t j = 0; j < BLOCK_LENGTH; ++j ) {
values[j / 4] |= ( bytes[i * BLOCK_LENGTH + j] & 0xff ) << ( ( 3 - j % 4 ) * 8 );
}
for ( uint32_t j = 16; j < 80; ++j ) {
values[j] = std::rotl
}
for ( uint32_t j = 0; j < 80; ++j ) {
switch ( j / 20 ) {
case 0 : { f = ( b & c ) | ( ~b & d ); k = 0x5a827999; break; }
case 1 : { f = b ^ c ^ d; k = 0x6ed9eba1; break; }
case 2 : { f = ( b & c ) | ( b & d ) | ( c & d ); k = 0x8f1bbcdc; break; }
case 3 : { f = b ^ c ^ d; k = 0xca62c1d6; break; }
}
e = d; d = c; c = std::rotl
}
Line 1,207:
std::stringstream stream;
for ( uint32_t i = 0; i < 20; ++i ) {
int8_t byte_value = static_cast<int8_t>
stream << std::setfill('0') << std::setw(2) << std::hex << ( byte_value &
}
return stream.str();
Line 1,229:
}
return bytes;
}
Line 3,163 ⟶ 3,153:
{{libheader|Wren-crypto}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
import "./fmt" for Fmt
var strings = [
|