Created
January 25, 2023 21:00
-
-
Save figadore/f74fbadca63d129ec0c7c69ec8b5440e to your computer and use it in GitHub Desktop.
experiment in cryptographic methods
This file contains 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
javascript: (function() { | |
var lowers = "abcdefghjkmnpqrstuvwxyz"; | |
var capitals = "ABCDEFGHJKLMNPQRSTUVWXYZ"; | |
var numbers = "123456789"; | |
var specials = '[(){$<#]\/?}>-=_+!*&@;:,.^%'; | |
var letters = lowers + capitals + numbers + specials; | |
function hash(input) { | |
var hash = 0, | |
i, chr, len; | |
if (input.length == 0) return hash; | |
for (i = 0, len = input.length; i < len; i++) { | |
chr = input.charCodeAt(i); | |
hash = ((hash << 5) - hash) + chr; | |
hash = hash >>> 0; | |
} | |
return hash; | |
} | |
function generate(seed, length, available) { | |
seed = seed % 2147483647; | |
if (seed <= 0) { | |
seed += 2147483646; | |
} | |
console.log("generating length " + length + " for seed " + seed); | |
var output = ""; | |
var i; | |
var index; | |
for (i = 0; i < length; i++) { | |
seed = seed * 16807 % 2147483647; | |
index = seed % available.length; | |
output = output + available.substring(index, index + 1); | |
} | |
return output; | |
} | |
function write(text) { | |
console.log("writing:" + text); | |
return text; | |
} | |
function route(input) { | |
console.log("generating hash for: " + input); | |
hashed = hash(input); | |
var generated = generate(hashed, outputLength, letters); | |
return generated; | |
} | |
input = prompt('input', ''); | |
var outputLength = prompt('length', ''); | |
prompt('result', route(input)) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment