Created
January 29, 2010 10:43
-
-
Save bytespider/289634 to your computer and use it in GitHub Desktop.
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
function ANSI_X923_pad(hex_str, blocksize) { | |
blocksize = blocksize || 512; // in bits | |
var bit_str_len = hex_str.length * 4; // in bits | |
var bit_str_len_hex = bit_str_len.toString(16); | |
// how many nibbles are left over? | |
var pad_nibbles = (((bit_str_len / blocksize) < 1) ? (blocksize - (bit_str_len_hex.length * 4)) - bit_str_len : (blocksize - (bit_str_len_hex.length * 4)) - (bit_str_len - blocksize)) / 4; | |
return hex_str + new Array(1 + pad_nibbles).join(0) + bit_str_len_hex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment