Points: 475

Tags: misc 

Poll rating:

Someone gave me two functions to convert strings into integers. I converted some strings to the integers and noted them down. Can you help me converting the concatenation of those strings in the order mentioned in the file hashes.txt into integers?

The answer for this is the multiplication of output of both the functions for the concatenated string. (Wrap the number around flag{})

File: hash.zip

You are given this source

mod = int(1e9 + 7)
mod2 = int(1e9 + 9)
import random

f = open("hashes.txt", "w")


def func1(s):
    h = 0
    for i in range(len(s)):
        h += (ord(s[i]) - 96) * pow(31, i, mod)
        h %= mod
    return h


def func2(s):
    h = 0
    for i in range(len(s)):
        h += (ord(s[i]) - 96) * pow(31, i, mod2)
        h %= mod2
    return h


def main():
    i = 0
    s = ""
    a1 = ""
    d = {}
    while i < 10000:
        x = random.randint(0, 19)
        a = random.randint(1, 1000)
        b = random.randint(a, a + 100)
        s1 = open("a/" + str(x)).read()[a - 1 : b]
        ha1 = func1(s1)
        ha2 = func2(s1)
        if d.get((ha1, ha2)) is not None:
            continue
        s += s1
        i += 1
        d[(ha1, ha2)] = 1
        a1 += str(ha1) + " " + str(ha2) + "\n"
    f.write(a1)
    f.close()
    # hsh1 = func1(s)
    # hsh2 = func2(s)
    # print(hsh1, hsh2)


if __name__ == "__main__":
    main()

And a list of hashes, as well as the a-folder with 20 1kb-files with the letters a-z.

Your task is to reverse all the hashes, concatenate the plaintext, hash it and multiply the 2 parts of the hash together. Wrap this in flag{hashmul} to get the flag.

Writeups

ActionRatingAuthor team
Read writeup
not rated
The Flat Network Society
Read writeup
not rated
OSUSEC
Read writeup
not rated
SIGFLAG
You need to authenticate and join a team to post writeups