summaryrefslogtreecommitdiff
path: root/include/py/homekit/camera/alinoname/HorrificallyBrokenPasswordFunction.py
blob: 94233821fdc4f6201cd9e6f6c1a8e217e6bde1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# numenworld-ipcam - Reverse engineering of the NuMenWorld NCV-I536A IP camera
# Copyright (C) 2019-2019 Johannes Bauer
#
# This file is part of numenworld-ipcam (https://github.com/johndoe31415/numenworld-ipcam).
#
# numenworld-ipcam is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; this program is ONLY licensed under
# version 3 of the License, later versions are explicitly excluded.
#
# numenworld-ipcam is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with numenworld-ipcam; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Johannes Bauer <JohannesBauer@gmx.de>

import hashlib


class HorrificallyBrokenPasswordFunction():
    @classmethod
    def derive(self, passphrase):
        alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
        assert (len(alphabet) == 62)
        passphrase = passphrase.encode("utf-8")
        hashval = hashlib.md5(passphrase).digest()
        encoded = ""
        for i in range(0, 16, 2):
            index = (hashval[i] + hashval[i + 1]) % len(alphabet)
            char = alphabet[index]
            encoded += char
        return encoded


if __name__ == "__main__":
    assert (HorrificallyBrokenPasswordFunction.derive("") == "tlJwpbo6")
    assert (HorrificallyBrokenPasswordFunction.derive("abc") == "LkM7s2Ht")