Last active
August 29, 2015 14:07
-
-
Save sergeevabc/f58ad888bebd7fbfd0c3 to your computer and use it in GitHub Desktop.
Filling string with chars N times (e.g. to test long vectors of hash functions) http://www.di-mgt.com.au/sha_testvectors.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// console.log(sha1(stringFill("a", 1000000))); | |
function stringFill(string, times) { | |
var result = ""; | |
for (;;) { | |
if (times & 1) result += string; | |
times >>= 1; | |
if (times) string += string; | |
else break; | |
} | |
return result; | |
} | |
// alternative | |
function repeatString(string, times) { | |
var result = ""; | |
while (times > 0) { | |
if (times & 1) result += string; | |
times >>= 1; | |
string += string; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment