<commit_before>var crypto = require('crypto'),
    ezcrypto = require('ezcrypto').Crypto;

speakeasy = {}

// speakeasy.hotp(options)
// calculates the one-time password given the key and a counter
// options.key                  the key
//        .counter              moving factor
//        .length(=6)           moving 
//        .encoding(='ascii')   key encoding (ascii, hex, or base32)
speakeasy.hotp = function(options) {
  // set vars
  var key = options.key;
  var counter = options.counter;
  var length = options.length || 6;
  var encoding = options.encoding || 'ascii';

  // preprocessing: convert to ascii if it's not
  if (encoding == 'hex') {
    key = speakeasy.hex_to_ascii(key);
  }

  // init hmac with the key
  var hmac = crypto.createHmac('sha1', new Buffer(key));
  
  // create an octet array from the counter
  var octet_array = new Array(8);

  var counter_temp = counter;

  for (i = 0; i < 8; i++) {
    i_from_right = 7 - i;

    // mask 255 over number to get last 8
    octet_array[i_from_right] = counter_temp & 255;
<commit_msg>added some documentation at the top<commit_after>// # speakeasy
// ### HMAC One-Time Password module for Node.js, supporting counter-based and time-based moving factors
// 
// speakeasy makes it easy to implement HMAC one-time passwords, supporting both counter-based (HOTP)
// and time-based moving factors (TOTP). It's useful for implementing two-factor authentication.
// Google and Amazon use TOTP to generate codes for use with multi-factor authentication.
//
// speakeasy also supports base32 keys/secrets, by passing `base32` in the `encoding` option.
// This is useful since Google Authenticator, Google's two-factor authentication mobile app
// available for iPhone, Android, and BlackBerry, uses base32 keys.
//
// This module was written to follow the RFC memos on HTOP and TOTP:
//
// * HOTP (HMAC-Based One-Time Password Algorithm): [RFC 4226](http://tools.ietf.org/html/rfc4226)
// * TOTP (Time-Based One-Time Password Algorithm): [RFC 6238](http://tools.ietf.org/html/rfc6238)

var crypto = require('crypto'),
    ezcrypto = require('ezcrypto').Crypto,
    base32 = require('base32');

speakeasy = {}

// speakeasy.hotp(options)
// calculates the one-time password given the key and a counter
// options.key                  the key
//        .counter              moving factor
//        .length(=6)           moving 
//        .encoding(='ascii')   key encoding (ascii, hex, or base32)
speakeasy.hotp = function(options) {
  // set vars
  var key = options.key;
  var counter = options.counter;
  var length = options.length || 6;
  var encoding = options.encoding || 'ascii';

  // preprocessing: convert to ascii if it's not
  if (encoding == 'hex') {
    key = speakeasy.hex_to_ascii(key);
  } else if (encoding == 'base32') {
    
  }

  // init hmac with the key
  var hmac = crypto.createHmac('sha1', new Buffer(key));
  
  // create an octet array from the counter
  var octet_array = new Array(8);

  var counter_temp = counter;

  for (i = 0; i < 8; i++) {
    i_from_right = 7 - i;

    // mask 255 over number to get last 8
    octet_array[i_from_right] = counter_temp & 255;

{'fraction_non_alphanumeric': 0.11994949494949494, 'fraction_numerical': 0.01893939393939394, 'mean_word_length': 2.850546780072904, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2307818', 'n_tokens_mistral': 1051, 'n_tokens_neox': 972, 'n_words': 333}