Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions decrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,43 @@ function loadWordList() {
return wordList;
}

function xmur3(str) {
for(var i = 0, h = 1779033703 ^ str.length; i < str.length; i++)
h = Math.imul(h ^ str.charCodeAt(i), 3432918353),
h = h << 13 | h >>> 19;
return function() {
h = Math.imul(h ^ h >>> 16, 2246822507);
h = Math.imul(h ^ h >>> 13, 3266489909);
return (h ^= h >>> 16) >>> 0;
}
}

function sfc32(a, b, c, d) {
return function() {
a >>>= 0; b >>>= 0; c >>>= 0; d >>>= 0;
var t = (a + b) | 0;
a = b ^ b >>> 9;
b = c + (c << 3) | 0;
c = (c << 21 | c >>> 11);
d = d + 1 | 0;
t = t + d | 0;
c = c + t | 0;
return (t >>> 0) / 4294967296;
}
}

var my_random = function() {
return Math.random;
}

_.random = function(min, max) {
if (max == null) {
max = min;
min = 0;
}
return min + Math.floor(my_random() * (max - min + 1));
};

function pickWords(numWords) {
return _.sample(wordList, numWords);
}
Expand Down Expand Up @@ -51,10 +88,23 @@ function loadCode() {
}
}

var seed = function() { return 0; };

function newGame() {
var seedkey = document.getElementById("gameseed").value;
if (seedkey.length > 0) {
seed = xmur3(seedkey);
} else {
seed = xmur3((new Date()).toJSON());
}
my_random = sfc32(seed(), seed(), seed(), seed());
var words = pickWords(4);
Cookies.set("words", words);
Cookies.remove("code");

seed = xmur3((new Date()).toJSON());
my_random = sfc32(seed(), seed(), seed(), seed());

$('#revealCodeButton').hide();
return words;
}
Expand Down Expand Up @@ -111,6 +161,9 @@ function initialize() {
wordList = loadWordList();
loadCode();

seed = xmur3((new Date()).toJSON());
my_random = sfc32(seed(), seed(), seed(), seed());

var words = loadWords();

if (words) {
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ <h5 class="modal-title" id="newGameModalLabel">New Game</h5>
</div>
<div class="modal-body">
Do you want to start a new game?
<p>Optional Game Key: <input type='text' id='gameseed'>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" id="newGameModalCancelButton">Cancel</button>
Expand Down