This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Colors { | |
static Reset :string = "\x1b[0m"; | |
static Bright :string = "\x1b[1m"; | |
static Underscore:string = "\x1b[4m"; | |
static Reverse :string = "\x1b[7m"; | |
//static Dim :string = "\x1b[2m";//does not work at all | |
//static Blink :string = "\x1b[5m";//does not work at all | |
//static Hidden :string = "\x1b[8m";//does not work at all | |
static R :string = "\x1b[0m"; | |
static B :string = "\x1b[1m"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { hmac256 } from "./HMAC"; | |
// implementation of HMAC-Based Key Derivation Function(HKDF) | |
// by Curse | |
// #region HKDF | |
// https://en.wikipedia.org/wiki/HKDF | |
// ikm = input key material | |
function hkdf_extract(salt, ikm) { | |
if (salt.length == 0) { | |
let newSalt = []; | |
for (let i = 0; i < 64; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { base32ToBytes, wordsToBytes } from "./numberHandling"; | |
import { hmac } from "./HMAC"; | |
// implementation of HMAC-Based One Time Password(HOTP) | |
// and Time Based One Time Password(TOTP) | |
// by Curse | |
const oneTimeDuration = 30 * 1000; // 30 seconds | |
const totpWindow = 1; | |
const hotpCodeLength = 6; | |
// #region TOTP | |
// https://en.wikipedia.org/wiki/Time-based_one-time_password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { stringToBytes } from "./numberHandling"; | |
import { sha1Bytes } from "./sha1"; | |
import { sha256Bytes } from "./sha256"; | |
// implementation of Hash-Based Message Authentication Code(HMAC) in javascript | |
// by Curse | |
// https://en.wikipedia.org/wiki/HMAC | |
export function hmac(key, message) { | |
if (typeof key == "string") | |
key = stringToBytes(key); | |
if (typeof message == "string") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { stringToBytes, bytesToBase16, bytesToWords, wordsToBytes } from "./numberHandling"; | |
// adapted from algorithm I found here https://stackoverflow.com/questions/59777670/how-can-i-hash-a-string-with-sha256, which was taken from https://geraintluff.github.io/sha256/ | |
// and from pseudo-code at https://en.wikipedia.org/wiki/SHA-2 | |
// by Curse | |
export function sha256(str) { | |
return bytesToBase16(sha256Bytes(stringToBytes(str))); | |
} | |
let h = []; | |
let k = []; | |
const maxWord = Math.pow(2, 32); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { stringToBytes, bytesToBase16, bytesToWords, wordsToBytes } from "./numberHandling"; | |
// adapted partially from algorithm I found here https://stackoverflow.com/questions/59777670/how-can-i-hash-a-string-with-sha256, which was taken from https://geraintluff.github.io/sha256/ | |
// and the wikipedia article on SHA-1 https://en.wikipedia.org/wiki/SHA-1 | |
// by Curse | |
export function sha1(str) { | |
return bytesToBase16(sha1Bytes(stringToBytes(str))); | |
} | |
// actual hash algorithms | |
function leftRotate(value, amount) { | |
return (value >>> (32 - amount)) | (value << amount); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { stringToBytes, bytesToBase16, bytesToWords, wordsToBytes } from "./numberHandling"; | |
// adapted partially from algorithm I found here https://stackoverflow.com/questions/59777670/how-can-i-hash-a-string-with-sha256, which was taken from https://geraintluff.github.io/sha256/ | |
// and the wikipedia article on SHA-1 https://en.wikipedia.org/wiki/SHA-1 | |
// by Curse | |
export function sha0(str) { | |
return bytesToBase16(sha0Bytes(stringToBytes(str))); | |
} | |
// actual hash algorithms | |
function leftRotate(value, amount) { | |
return (value >>> (32 - amount)) | (value << amount); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// general library for handling, converting, and generating numbers in other bases | |
// by Curse | |
function padStartToMod(str, mod, char) { | |
return char.repeat((mod - (str.length % mod)) % mod) + str; | |
} | |
function padEndToMod(str, mod, char) { | |
return str + char.repeat((mod - (str.length % mod)) % mod); | |
} | |
// base 16(hex) functions | |
const base16Chars = "0123456789ABCDEF"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adapted from my own sha256 algorithm and the instructions for conversion found at https://en.wikipedia.org/wiki/SHA-2 | |
// note: this only works on ascii text (which is the default in c++), and wouldnt working on anything like a wstring, or buffer of some kind | |
#include <string>// for std::string | |
#include <vector>// for std::vector<T> | |
#include <cmath>// for std::pow | |
const unsigned long long int maxWord = 1ULL<<32; | |
#include <iostream> | |
#include <iomanip> | |
std::string sha512(std::string str, bool debug) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adapted mostly from pseudo-code algorithm at https://en.wikipedia.org/wiki/MD5 | |
// with some slight help from chat-gpt, because I forgot about the little endian parts | |
// note: this only works on ascii text (which is the default in c++), and wouldnt working on anything like a wstring, or buffer of some kind | |
// from my tests this took roughly 0.025 milliseconds on average even on strings with a length of 500 characters | |
#include <string>// for std::string | |
#include <vector>// for std::vector<T> | |
#include <cmath>// for std::pow | |
const unsigned long long int maxWord = std::pow(2, 32); | |
std::string md5(std::string str) { |
NewerOlder