Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 4bb7036c626cf146eaf0d87dcf81988cad90198f
parent 00b888fb80b65d82c79ee82a54e853252ddf69e1
Author: danyisill <danyisill@users.noreply.github.com>
Date:   Sun, 22 Mar 2020 22:14:50 +0300

switch to a better hash function

Diffstat:
Mlib/commands/ship.ts | 17++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/commands/ship.ts b/lib/commands/ship.ts @@ -1,4 +1,4 @@ -import crypto from 'crypto'; +import { createHash } from 'crypto'; import { FORMATS } from '../extensions'; import { Message, Attachment, RichEmbed } from 'discord.js'; @@ -22,7 +22,12 @@ const RESPONSES = [ { range: [93, 97], message: "They deeply love each other! :blush:" }, { range: [97, 100], message: "Lovey-dovey couple!! :kissing_heart: :heart: :two_hearts:" }, ]; - +function read512bitsBigIntBigEndian(buffer){ + let biiiiiiiigInt = BigInt(0); + for (var i = 512 + 64; i -= 64;) + biiiiiiiigInt += cryptoBuffer.readBigUInt64BE(i / 8 - 8) * BigInt(Math.pow(2, i)); + return biiiiiiiigInt; +} export default home_scope => { const { message, args, HELP_SECTIONS, @@ -76,11 +81,9 @@ export default home_scope => { return `${percentage} ${progress_bar}`; }; - const die = crypto - .createHash('md5') - .update(users.reduce((a, c) => - a + BigInt(c.id), BigInt(0)) - .toString()).digest().readUInt16LE() % 101; + const die = Number(read512bitsBigIntBigEndian(createHash('sha512') + .update(users.reduce((a, c) => a + BigInt(c.id), BigInt(0)) + .toString()).digest()) % BigInt(101)); // ^ < 80 cols const response = `${get_percentage(die)} ${get_response(die)}`;