Search code examples
hashpassword-hashmit-scratch

Generating the same password for any given string?


Good morning/afternoon/evening guys!

So I've been assigned for a class the following task: make a Scratch (:/ not the funnest language lol) program that takes an input string, and outputs a password. However, the password should be reproduceable using the same seed. I did some searching and found this article saying that this is called hashing. Cool, I'm pretty sure this is what I need to do.

Here's the problem: using that to generate a password. So I have code that works that generates a unique random password here. I should be able to adapt that easily.

My current thought process is: if I take the ASCII value of the character and multiply by a prime number and then multiply by the character index of it (something like (64 * 239 * 1) + (85 * 239 * 2)), I should get a unique number for most strings (right?). Then I add them up and use that number to do something and generate a 6-7 character password.

What can I do to take this basic hash and get a 6-7 character password (a-z, A-Z, !, $, and % for my charset but don't worry about that part). More-so, how might I do this in Scratch?

Thanks!


Solution

  • Here is something that I made:
    This is the code I made

    What it does is iterate through the string and check it against each item in the alphabet by iterating through it and then when it finds a match it will do the math and add the value to the hash. Is this what you were looking for? I hope it helps. ASCII list:

    1  97
    2  98
    3  99
    4  100
    5  101
    6  102
    7  103
    8  104
    9  105
    10 106
    11 107
    12 108
    13 109
    14 110
    15 111
    16 112
    17 113
    18 114
    19 115
    20 116
    21 117
    22 118
    23 119
    24 120
    25 121
    26 122
    27 37
    28 33
    29 36