Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HSIMP.observer = function () {
- "use strict";
- var object = {}, observers = {}, uID = 1;
- object.addObserver = function (o) {
- var i, observer, id = uID;
- if (typeof o != "function") throw new Error("Observer must be a function");
- for (i in observers) if (observers.hasOwnProperty(i)) {
- observer = observers[i];
- if (observer === o) throw new Error("Observer already in the list")
- }
- observers[id] = o;
- uID += 1;
- return id
- };
- object.removeObserver = function (id) {
- if (observers[id]) {
- observers[id] = undefined;
- return
- }
- throw new Error("Could not find observer in list of observers")
- };
- object.notifyObservers = function (data) {
- var i;
- for (i in observers) observers.hasOwnProperty(i) && observers[i](data)
- };
- return object
- };
- HSIMP.calculator = function (d, translate) {
- "use strict";
- var o = {}, observer = HSIMP.observer(),
- matches = function () {
- var matches = [],
- add = function (name, match, length) {
- matches.push({
- name: name,
- match: match,
- length: length
- })
- };
- add("ASCII Lowercase", /[a-z]/, 26);
- add("ASCII Uppercase", /[A-Z]/, 26);
- add("ASCII Numbers", /\d/, 10);
- add("ASCII Top Row Symbols", /[!@£#\$%\^&\*\(\)\-_=\+]/, 15);
- add("ASCII Other Symbols", /[\?\/\.>\,<`~\\|"';:\]\}\[\{\s]/, 19);
- add("Unicode Latin 1 Supplement", /[\u00A1-\u00FF]/, 94);
- add("Unicode Latin Extended A", /[\u0100-\u017F]/, 128);
- add("Unicode Latin Extended B", /[\u0180-\u024F]/, 208);
- add("Unicode Latin Extended C", /[\u2C60-\u2C7F]/, 32);
- add("Unicode Latin Extended D", /[\uA720-\uA7FF]/, 29);
- add("Unicode Cyrillic Uppercase", /[\u0410-\u042F]/, 32);
- add("Unicode Cyrillic Lowercase", /[\u0430-\u044F]/, 32);
- return matches
- }(),
- v = {
- time: 0,
- calcs: 25e7,
- characters: 0,
- combinations: 0,
- characterSets: [],
- cost: 0,
- storage: 0
- }, password = "",
- combinations = function () {
- v.length = password.length;
- if (v.length) {
- v.combinations = Math.pow(v.characters, v.length);
- v.storage = v.combinations / 1e4;
- v.cost = v.combinations / 4e5 * (.28 / 60)
- } else {
- v.storage = 0;
- v.combinations = 0;
- v.cost = 0
- }
- }, characters = function () {
- var i, len = matches.length;
- v.characterSets = [];
- v.characters = 0;
- for (i = 0; i < len; i += 1) if (password.match(matches[i].match)) {
- v.characters += matches[i].length;
- v.characterSets.push(matches[i].name)
- }
- }, time = function () {
- combinations();
- v.time = v.combinations / v.calcs
- };
- o.setPassword = function (p) {
- password = p;
- characters();
- time();
- observer.notifyObservers()
- };
- o.setCalcs = function (c) {
- c || (c = 1);
- v.calcs = c;
- time();
- observer.notifyObservers()
- };
- o.getValue = function (name) {
- return v[name]
- };
- o.addObserver = observer.addObserver;
- return o
- };
- HSIMP.checks = function () {
- var o = {}, password = "",
- checks = [],
- ob = HSIMP.observer(),
- insecure = !1,
- warning = !1,
- check = function () {
- var i, len = checks.length,
- data = [],
- result, rank = {
- achievement: 1,
- advice: 2,
- warning: 3,
- insecure: 4
- }, sort = function (a, b) {
- return rank[a.type] < rank[b.type] ? 1 : -1
- };
- insecure = !1;
- warning = !1;
- for (i = 0; i < len; i += 1) {
- result = checks[i]();
- if (result) {
- data.push(result);
- result.type === "insecure" ? insecure = !0 : result.type === "warning" && (warning = !0)
- }
- }
- data.sort(sort);
- ob.notifyObservers(data)
- };
- checks.push(function () {
- var i, len = HSIMP.commonPasswords.length,
- rank;
- for (i = 0; i < len; i += 1) if (password.toLowerCase() === HSIMP.commonPasswords[i]) {
- rank = Math.ceil((i + 1) / 10) * 10;
- return {
- title: "Common Password: In the top " + rank + " most used passwords",
- type: "insecure",
- wording: "Your password is very commonly used. It would be cracked almost instantly."
- }
- }
- });
- checks.push(function () {
- var results = password.match(/(.+)\1{2,}/gi);
- if (results) return {
- title: "Repeated Pattern",
- type: "warning",
- wording: "Repeated characters or patterns can make your password more predictable"
- }
- });
- checks.push(function () {
- if (password.match(/^[A-Za-z]+$/)) return {
- title: "Character Variety: Just Letters",
- type: "advice",
- wording: "Your password only contains letters. Adding numbers and symbols can make your password more secure."
- };
- if (password.match(/^[A-Za-z0-9]+$/)) return {
- title: "Character Variety: No Symbols",
- type: "advice",
- wording: "Your password only contains numbers and letters. Adding a symbol can make your password more secure. Don't forget you can often use spaces in passwords."
- };
- if (password.match(/[^A-Za-z0-9\u0000-\u007E]/)) return {
- title: "Character Variety: Non-Standard Character",
- type: "achievement",
- wording: "Your password contains a non-keyboard character. This should make it more secure."
- }
- });
- checks.push(function () {
- if (password.length < 5) return {
- title: "Length: Very short",
- type: "warning",
- wording: "Your password is very short. The longer a password is the more secure it will be."
- };
- if (password.length < 8) return {
- title: "Length: Short",
- type: "advice",
- wording: "Your password is quite short. The longer a password is the more secure it will be."
- };
- if (password.length > 15) return {
- title: "Length: Long",
- type: "achievement",
- wording: "Your password is over 16 characters long. It should be pretty safe."
- }
- });
- checks.push(function () {
- if (password.match(/^[a-zA-Z]+$/)) return {
- title: "Possibly a Word",
- type: "warning",
- wording: "Your password looks like it could be a dictionary word or a name. If it's a name with personal significance it might be easy to guess. If it's a dictionary word it could be cracked very quickly."
- }
- });
- checks.push(function () {
- if (password.match(/^[\-\(\)\.\/\s0-9]+$/)) return {
- title: "Possibly a Telephone Number / Date",
- type: "warning",
- wording: "Your password looks like it might be a telephone number or a date. If it is and it has personal significance then it might be very easy for someone to guess."
- }
- });
- checks.push(function () {
- if (password.match(/^[a-zA-Z]+[0-9]+$/) || password.match(/^[0-9]+[a-zA-Z]+$/)) return {
- title: "Possibly a Word and a Number",
- type: "warning",
- wording: "Your password looks like it might just be a word and a few digits. This is a very common pattern and would be cracked very quickly."
- }
- });
- o.setPassword = function (p) {
- password = p;
- check()
- };
- o.insecure = function () {
- return insecure
- };
- o.warning = function () {
- return warning
- };
- o.addObserver = ob.addObserver;
- return o
- };
- HSIMP.format = function () {
- "use strict";
- var o = {}, named = !0,
- reference = {};
- reference.bytes = {};
- reference.bytes.dictionary = {
- kilobyte: 1024,
- megabyte: Math.pow(1024, 2),
- gigabyte: Math.pow(1024, 3),
- terabyte: Math.pow(1024, 4),
- petabyte: Math.pow(1024, 5),
- exabyte: Math.pow(1024, 6),
- zettabyte: Math.pow(1024, 7),
- yottabyte: Math.pow(1024, 8),
- brontobyte: Math.pow(1024, 9),
- geopbyte: Math.pow(1024, 10)
- };
- reference.bytes.array = function () {
- var bytes = function (name, value) {
- return {
- name: name,
- value: value
- }
- }, sort = function (a, b) {
- return a.value < b.value ? -1 : 1
- }, numbers = reference.bytes.dictionary,
- array = [],
- i;
- for (i in numbers) numbers.hasOwnProperty(i) && array.push(bytes(i, numbers[i]));
- array.sort(sort);
- return array
- }();
- reference.largeNumbers = {};
- reference.largeNumbers.dictionary = {
- thousand: 1e3,
- million: 1e6,
- billion: 1e9,
- trillion: 1e12,
- quadrillion: 1e15,
- quintillion: 1e18,
- sextillion: 1e21,
- septillion: 1e24,
- octillion: 1e27,
- nonillion: 1e30,
- decillion: 1e33,
- undecillion: 1e36,
- duodecillion: 1e39,
- tredecillion: 1e42,
- quattuordecillion: 1e45,
- quindecillion: 1e48,
- sexdecillion: 1e51,
- septendecillion: 1e54,
- octodecillion: 1e57,
- novemdecillion: 1e60,
- vigintillion: 1e63,
- unvigintillion: 1e66,
- duovigintillion: 1e69,
- tresvigintillion: 1e72,
- quattuorvigintillion: 1e75,
- quinquavigintillion: 1e78,
- sesvigintillion: 1e81,
- septemvigintillion: 1e84,
- octovigintillion: 1e87,
- novemvigintillion: 1e90,
- trigintillion: 1e93,
- untrigintillion: 1e96,
- duotrigintillion: 1e99,
- googol: 1e100,
- trestrigintillion: 1e102,
- quattuortrigintillion: 1e105,
- quinquatrigintillion: 1e108,
- sestrigintillion: 1e111,
- septentrigintillion: 1e114,
- octotrigintillion: 1e117,
- noventrigintillion: 1e120,
- quadragintillion: 1e123,
- quinquagintillion: 1e153,
- sexagintillion: 1e183,
- septuagintillion: 1e213,
- octogintillion: 1e243,
- nonagintillion: 1e273
- };
- reference.largeNumbers.array = function () {
- var number = function (name, value) {
- return {
- name: name,
- value: value
- }
- }, sort = function (a, b) {
- return a.value < b.value ? -1 : 1
- }, numbers = reference.largeNumbers.dictionary,
- array = [],
- i;
- for (i in numbers) numbers.hasOwnProperty(i) && array.push(number(i, numbers[i]));
- array.sort(sort);
- return array
- }();
- o.number = function (number) {
- var rgx = /(\d+)(\d{3})/,
- split, integer, decimal, magnitude, exponent, numbers = reference.largeNumbers.array,
- len = numbers.length,
- i = 0,
- decimalPlaces = 0,
- repeatString = function (s, t) {
- var r = "",
- i = 0;
- for (i; i < t; i += 1) r += s;
- return r
- }, exponentiate = function (n) {
- var string = n.toString(),
- exp = string.match(/^([\d\.]+)e([\-\+]?)(\d+)$/),
- split, len;
- if (!exp) return string;
- string = exp[1];
- if (exp[2] === "-") if (string.match(/\./)) {
- split = string.split(".");
- len = split[0].length;
- len < exp[3] ? string = "0." + repeatString("0", exp[3] - len) + split[0] + split[1] : string = split[0].substr(0, len - exp[3]) + "." + split[0].substr(len - exp[3]) + split[1]
- } else string = "0." + repeatString("0", exp[3] - 1) + string;
- else if (string.match(/\./)) {
- split = string.split(".");
- len = split[1].length;
- len < exp[3] ? string = split[0] + split[1] + repeatString("0", exp[3] - len) : string = split[0] + split[1].substr(0, exp[3])
- } else string += repeatString("0", exp[3]);
- return string
- }, mag = function () {
- var numbers = reference.largeNumbers.array,
- i, len = numbers.length,
- magnitude = "";
- if (!number || isNaN(number) || number === Infinity) return;
- while (number >= numbers[0].value) {
- for (i = 0; i < len; i += 1) if (number < numbers[i].value) break;
- i -= 1;
- number /= numbers[i].value;
- magnitude = numbers[i].name + (magnitude ? " " : "") + magnitude
- }
- return magnitude
- };
- named && (magnitude = mag());
- number < 1 && (decimalPlaces = 10);
- number = exponentiate(number);
- split = number.split(".");
- integer = split[0];
- decimalPlaces ? decimal = split.length > 1 ? "." + split[1] : "" : decimal = "";
- while (rgx.test(integer)) integer = integer.replace(rgx, "$1,$2");
- return (integer + decimal.substr(0, decimalPlaces + 1) + " " + (magnitude || "")).replace(/^\s+|\s+$/g, "")
- };
- o.convert = function (string) {
- var nums = reference.largeNumbers.dictionary,
- replace = function (match) {
- var value, exp, i = 0;
- if (nums[match]) {
- value = nums[match];
- value += "";
- exp = value.match(/^1e\+([\d]+)$/);
- if (exp && exp[1]) {
- value = "";
- for (i; i < exp[1]; i += 1) value += "0"
- } else value = value.replace(/^1/, "");
- return value
- }
- };
- string = string.replace(/[a-zA-z]+/g, replace);
- string = string.replace(/[^\d\.]/g, "");
- return string
- };
- o.periods = function (time) {
- var period = function (period, inSecs, useAn) {
- useAn = useAn || !1;
- return {
- period: period,
- inSecs: inSecs,
- useAn: useAn
- }
- }, periods = [period("second", 1), period("minute", 60), period("hour", 3600, !0), period("day", 86400), period("year", 31556926)],
- length = periods.length;
- return function (time) {
- var format = o,
- result = "",
- period = "",
- i = 0;
- result = format.number(time) + " seconds";
- for (i; i < length; i += 1) {
- if (time < periods[i].inSecs) break;
- result = format.number(time / periods[i].inSecs);
- result !== "1" && result !== 1 ? period = " " + periods[i].period + "s" : period = " " + periods[i].period;
- if (result.match(/^1 /) || result.match(/^1$/)) periods[i].useAn || result.match(/^1 [aeiou]/i) ? result = result.replace(/^1/, "An") : result = result.replace(/^1/, "A");
- result = result + " " + period
- }
- return result
- }
- }();
- o.bytes = function (bytes) {
- var storage = reference.bytes.array,
- format = o,
- plural = "",
- length = storage.length,
- i = 0,
- result = bytes + " bytes";
- for (i; i < length; i += 1) {
- if (bytes < storage[i].value) break;
- result = bytes / storage[i].value;
- result !== 1 && (plural = "s");
- result = format.number(result) + " " + storage[i].name + plural
- }
- return result
- };
- o.setNamed = function (v) {
- named = v
- };
- return o
- };
- HSIMP.app = function ($scope) {
- "use strict";
- var calculator = HSIMP.calculator(),
- formatter = HSIMP.format(),
- checks = HSIMP.checks(),
- html = document.getElementsByTagName("html")[0],
- updatePassword = function () {
- var timeInSecs = calculator.getValue("time");
- $scope.time = formatter.periods(timeInSecs);
- $scope.possibleCombinations = formatter.number(calculator.getValue("combinations"));
- $scope.characters = formatter.number(calculator.getValue("characters"));
- $scope.calcsPerSecond = formatter.number(calculator.getValue("calcs"));
- timeInSecs === 0 ? html.className = "" : timeInSecs < 1020 ? html.className = "bad" : timeInSecs < 307584e5 ? html.className = "ok" : html.className = "good"
- }, updateChecks = function (c) {
- $scope.checks = c;
- if (checks.insecure()) {
- html.className = "bad";
- $scope.time = "Instantly";
- $scope.insecure = !0
- } else $scope.insecure = !1
- };
- $scope.insecure = !1;
- $scope.characters = 0;
- $scope.possibleCombinations = 0;
- $scope.display = {};
- $scope.display.config = !0;
- $scope.display.details = !0;
- $scope.display.toggleConfig = function () {
- if ($scope.display.config) {
- $scope.display.config = !1;
- $scope.display.configText = "Show Settings"
- } else {
- $scope.display.config = !0;
- $scope.display.configText = "Hide Settings"
- }
- return !1
- };
- $scope.display.toggleDetails = function () {
- if ($scope.display.details) {
- $scope.display.details = !1;
- $scope.display.detailsText = "Show Details"
- } else {
- $scope.display.details = !0;
- $scope.display.detailsText = "Hide Details"
- }
- return !1
- };
- $scope.display.toggleConfig();
- $scope.display.toggleDetails();
- $scope.config = {};
- $scope.config.namedNumbers = !0;
- $scope.config.calculations = "4 billion";
- $scope.config.calculationsOriginal = !0;
- $scope.config.changeNamedNumbers = function () {
- formatter.setNamed($scope.config.namedNumbers);
- calculator.setPassword($scope.password)
- };
- $scope.config.changeCalculations = function () {
- $scope.config.calculationsOriginal = !1;
- calculator.setCalcs(formatter.convert($scope.config.calculations))
- };
- calculator.setCalcs(formatter.convert($scope.config.calculations));
- $scope.lang = HSIMP.language.en.translations;
- calculator.addObserver(updatePassword);
- checks.addObserver(updateChecks);
- $scope.passwordChange = function () {
- $scope.length = $scope.password.length;
- calculator.setPassword($scope.password);
- checks.setPassword($scope.password)
- }
- };
- (function () {
- "use strict";
- var passwordInput = document.getElementById("password"),
- nojs = document.getElementById("no-js");
- document.getElementById("js").setAttribute("style", "display: block");
- nojs.parentNode.removeChild(nojs);
- passwordInput.focus()
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement