Created
August 16, 2025 01:11
-
-
Save WindClan/7ca6399397fae5a736dbe3e0a11436d8 to your computer and use it in GitHub Desktop.
Terrible Hashing Algorithm
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
| local function getTranslatedMessage(mode, message, key) --https://santoslove.github.io/caesarcipher.html | |
| if mode:sub(1, 1) == 'd' then | |
| key = -key | |
| end | |
| translated = '' | |
| for i = 1, #message do | |
| local symbol = message:sub(i,i) | |
| if symbol == symbol:match('%a') then | |
| num = string.byte(symbol) | |
| num = num + key | |
| if symbol == symbol:upper() then | |
| if num > string.byte('Z') then | |
| num = num - 26 | |
| elseif num < string.byte('A') then | |
| num = num + 26 | |
| end | |
| elseif symbol == symbol:lower() then | |
| if num > string.byte('z') then | |
| num = num - 26 | |
| elseif num < string.byte('a') then | |
| num = num + 26 | |
| end | |
| end | |
| translated = translated .. string.char(num) | |
| else | |
| translated = translated .. symbol | |
| end | |
| end | |
| return translated | |
| end | |
| local function getKey(l) | |
| while l > 26 do | |
| l = l - 26 | |
| end | |
| return l | |
| end | |
| local function hash(p) | |
| local l = p:len() | |
| local p = p:gsub('[%p%c%s]', '') | |
| math.randomseed(l*l) | |
| if l > 16 then | |
| error("Invalid password length!") | |
| elseif l < 16 then | |
| while p:len() < 16 do | |
| local char = "" | |
| if math.random(1,5) == 1 then | |
| char = 64 + math.random(1,26) | |
| else | |
| char = 96 + math.random(1,26) | |
| end | |
| p = p .. string.char(char) | |
| end | |
| end | |
| local mode = " " | |
| if l % 2 == 0 then | |
| mode = "d" | |
| end | |
| return getTranslatedMessage(mode,p,getKey(l)) | |
| end | |
| term.write("Enter Password: ") | |
| print(hash(read())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment