Skip to content

Instantly share code, notes, and snippets.

@sergeevabc
Last active August 29, 2015 14:07
Show Gist options
  • Save sergeevabc/f58ad888bebd7fbfd0c3 to your computer and use it in GitHub Desktop.
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
// 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