123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
<div class="container">
  <div class="input">
    <label for="name">Nom de dresseur</label>
    <input name="name" maxlength="7"/>
  </div>
  <div class="input">
    <label for="id">Numéro ID</label>
    <input name="id" maxlength="5"/>
  </div>
  <div class="input">
    <label for="currentCash">Argent total</label>
    <input name="currentCash" maxlength="6"/>
  </div>
  <div class="input">
    <label for="password">Password</label>
    <input name="password" readonly="readonly"/>
  </div>
</div>
            
          
!
            
              @import url(//fonts.googleapis.com/css?family=Ubuntu);
@import url(//fonts.googleapis.com/css?family=Ubuntu+Mono);

html, body {
  height          : 100%;
  width           : 100%;
}

body {
  align-items      : center;
  background-color : #e4eff5;
  color            : #0581e5;
  display          : flex;
  font-family      : Ubuntu, sans-serif;
  margin           : 0 auto;
  padding          : 0;
}

.container {
  margin : auto;
}

.input {
  padding : 15px;
}

label {
  display   : block;
  font-size : 1.5em;
}

input {
  background-color : #e4eff5;
  border           : 0;
  border-bottom    : solid 3px;
  color            : #4cacfb;
  font-family      : "Ubuntu Mono", monospace;
  height           : 20px;
  width            : 125px;
  padding          : 10px 10px;
  font-size        : 1.25em;
}

input:focus {
  outline: none;
}

input[name="currentCash"], input[name="id"] {
  text-align: left;
}

::selection {
  background : #8828B0;
  color      : #9ACCF2;
}

            
          
!
            
              (function() {
/***
 * Calculate the time reset code for Pokémon Crystal.
 * 
 * Purpose: Take the trainer's name, currently held cash, and ID
 *   number, returning a five digit ID number. 
 * 
 *  1) Map the first five characters of the trainer's name to an
 *     arbitrary set of numbers.
 *  2) Add those values together to get a single value.
 *  3) If the current cash is greater than 65535, get the modulus.
 *  4) Integer divide the current cash or modulus by 256.
 *  5) Add the modulus of that number and 256 to the result of the
 *     previous step.
 *  6) If the ID is greater than 65535, subtract the current
 *     cash from the ID until it is less than 65535.
 *  7) Integer divide the ID number or modulus by 256. 
 *  8) Add the modulus of that number and 256 to the result of the
 *     previous step.
 *  9) Zero pad the result from each input.
 */

var CALC = CALC || {};

CALC.magicValue = 65535;
CALC.inputNames = ["name", "currentCash", "id"];
CALC.inputs = {};
CALC.values = {};
CALC.charMap = {
  // Uppercase
    "A": 128, "B": 129, "C": 130, "D": 131, "E": 132, "F": 133, "G": 134
  , "H": 135, "I": 136, "J": 137, "K": 138, "L": 139, "M": 140, "N": 141
  , "O": 142, "P": 143, "Q": 144, "R": 145, "S": 146, "T": 147, "U": 148
  , "V": 149, "W": 150, "X": 151, "Y": 152, "Z": 153
  // Lowercase
  , "a": 160, "b": 161, "c": 162, "d": 163, "e": 164, "f": 165, "g": 166
  , "h": 167, "i": 168, "j": 169, "k": 170, "l": 171, "m": 172, "n": 173
  , "o": 174, "p": 175, "q": 176, "r": 177, "s": 178, "t": 179, "u": 180
  , "v": 181, "w": 182, "x": 183, "y": 184, "z": 185
};

CALC.outputName = "password";

/***
 * Pad a number with zeroes or a given character by a given amount.
 * http://stackoverflow.com/a/10073788/2305229
 ***/
CALC.pad = function(n, width, z)
{
  z = z || '0';
  n = n + '';
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
};

CALC.addHandlers = function(inputNames)
{
  for (var i = 0; i < inputNames.length; i++)
  {
    CALC.inputs[inputNames[i]] = document.getElementsByName(inputNames[i])[0];
    CALC.inputs[inputNames[i]].addEventListener(
         "keyup"
       , this.calculatePassword
       , false
     );
  }
};

CALC.getNameBasedValue = function(name)
{
  nameCharsLength = (name.length < 5 ? name.length : 5);
  nameChars = name.substring(0, nameCharsLength);
  nameVal = 0;
  for (var i = 0; i < nameCharsLength; i++)
  {
    nameVal = nameVal + CALC.charMap[nameChars[i]];
  }
  return nameVal;
};

CALC.getCashBasedValue = function(cash)
{
  cashVal = cash;
  if (CALC.magicValue < cash)
  {
    cashVal = cash % CALC.magicValue;
  }
  return ~~(cashVal/256) + cashVal % 256;
};

CALC.getIdBasedValue = function(id)
{
  idVal = CALC.adjustValueBelowThreshold(
        id
      , CALC.inputs.currentCash.value
      , CALC.magicValue
    );
  return ~~(idVal/256) + idVal % 256;
};

CALC.adjustValueBelowThreshold = function(value, adjustment, threshold)
{
  while (threshold < value)
  {
    value = value - adjustment;
  }
  return value;
};

CALC.calculatePassword = function(event)
{
  event.preventDefault;
  var password = 0;
  console.log(CALC.values.name);
  if (CALC.inputs.name.value.length > 0
    && CALC.inputs.currentCash.value.length > 0
    && CALC.inputs.id.value.length > 0)
  {
    CALC.values.name = CALC.getNameBasedValue(CALC.inputs.name.value);
    CALC.values.currentCash = CALC.getCashBasedValue(CALC.inputs.currentCash.value);
    CALC.values.id = CALC.getIdBasedValue(CALC.inputs.id.value);
    Object.keys(CALC.values).forEach(function(value) {
      password = password + CALC.values[value];
    });
    CALC.writePassword(password);
  }
};

CALC.writePassword = function(password)
{
  document.getElementsByName(this.outputName)[0].value = CALC.pad(password, 5);
};

CALC.init = function()
{
  this.addHandlers(this.inputNames);
  // document.getElementsByName("name")[0].focus();
};

CALC.init();
})();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console