A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d8/d7a/sha1_8cpp_source.html below:

TheAlgorithms/C++: hashing/sha1.cpp Source File

59 return

(n << rotate) | (n >> (32 - rotate));

68 const char

* hexChars =

"0123456789abcdef"

;

69 auto

* intsig =

static_cast<

uint8_t*

>

(sig);

70

std::string hex =

""

;

71 for

(uint8_t i = 0; i < 20; i++) {

72

hex.push_back(hexChars[(intsig[i] >> 4) & 0xF]);

73

hex.push_back(hexChars[(intsig[i]) & 0xF]);

84void

*

hash_bs

(

const void

* input_bs, uint64_t input_size) {

85 auto

* input =

static_cast<const

uint8_t*

>

(input_bs);

88

uint32_t h0 = 0x67452301, a = 0;

89

uint32_t h1 = 0xEFCDAB89, b = 0;

90

uint32_t h2 = 0x98BADCFE, c = 0;

91

uint32_t h3 = 0x10325476, d = 0;

92

uint32_t h4 = 0xC3D2E1F0, e = 0;

97

uint64_t padded_message_size = 0;

98 if

(input_size % 64 < 56) {

99

padded_message_size = input_size + 64 - (input_size % 64);

101

padded_message_size = input_size + 128 - (input_size % 64);

105

std::vector<uint8_t> padded_message(padded_message_size);

108

std::copy(input, input + input_size, padded_message.begin());

111

padded_message[input_size] = 1 << 7;

112 for

(uint64_t i = input_size; i % 64 != 56; i++) {

113 if

(i == input_size) {

116

padded_message[i] = 0;

121

uint64_t input_bitsize = input_size * 8;

122 for

(uint8_t i = 0; i < 8; i++) {

123

padded_message[padded_message_size - 8 + i] =

124

(input_bitsize >> (56 - 8 * i)) & 0xFF;

128

std::array<uint32_t, 80> blocks{};

131 for

(uint64_t chunk = 0; chunk * 64 < padded_message_size; chunk++) {

133 for

(uint8_t bid = 0; bid < 16; bid++) {

138 for

(uint8_t cid = 0; cid < 4; cid++) {

139

blocks[bid] = (blocks[bid] << 8) +

140

padded_message[chunk * 64 + bid * 4 + cid];

144 for

(uint8_t i = 16; i < 80; i++) {

147

blocks[i - 14] ^ blocks[i - 16],

159 for

(uint8_t i = 0; i < 80; i++) {

160

uint32_t F = 0, g = 0;

162

F = (b & c) | ((~b) & d);

168

F = (b & c) | (b & d) | (c & d);

194 auto

* sig =

new

uint8_t[20];

195 for

(uint8_t i = 0; i < 4; i++) {

196

sig[i] = (h0 >> (24 - 8 * i)) & 0xFF;

197

sig[i + 4] = (h1 >> (24 - 8 * i)) & 0xFF;

198

sig[i + 8] = (h2 >> (24 - 8 * i)) & 0xFF;

199

sig[i + 12] = (h3 >> (24 - 8 * i)) & 0xFF;

200

sig[i + 16] = (h4 >> (24 - 8 * i)) & 0xFF;

211void

*

hash

(

const

std::string& message) {

212 return hash_bs

(&message[0], message.size());

224

std::cout <<

"Hashing empty string"

<< std::endl;

229 "da39a3ee5e6b4b0d3255bfef95601890afd80709"

) == 0);

234

std::cout <<

"Hashing The quick brown fox jumps over the lazy dog" 240 "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"

) == 0);

246

std::cout <<

"Hashing " 247 "The quick brown fox jumps over the lazy dog." 253 "408d94384216f890ff7a0c3528e8bed1e0b01621"

) == 0);

258 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

);

261 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 267 "761c457bf73b14d27e9e9265c46f4b4dda11f940"

) == 0);

278

std::cout <<

"Enter a message to be hashed (Ctrl-C to exit): " 280

std::getline(std::cin, input);

285

std::cout <<

"Want to enter another message? (y/n) "

;

286

std::getline(std::cin, input);

287 if

(input.compare(

"y"

) == 0) {

289

}

else if

(input.compare(

"n"

) == 0) {


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4