blob: e31548e7660cb860e9dad6bc14e27981ea796a15 (
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
43
44
45
|
# tsuserver3, an Attorney Online server
#
# Copyright (C) 2016 argoneus <argoneuscze@gmail.com>
#
# This program 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, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
# fantacrypt was a mistake, just hardcoding some numbers is good enough
import binascii
CRYPT_CONST_1 = 53761
CRYPT_CONST_2 = 32618
CRYPT_KEY = 5
def fanta_decrypt(data):
data_bytes = [int(data[x:x + 2], 16) for x in range(0, len(data), 2)]
key = CRYPT_KEY
ret = ''
for byte in data_bytes:
val = byte ^ ((key & 0xffff) >> 8)
ret += chr(val)
key = ((byte + key) * CRYPT_CONST_1) + CRYPT_CONST_2
return ret
def fanta_encrypt(data):
key = CRYPT_KEY
ret = ''
for char in data:
val = ord(char) ^ ((key & 0xffff) >> 8)
ret += binascii.hexlify(val.to_bytes(1, byteorder='big')).decode().upper()
key = ((val + key) * CRYPT_CONST_1) + CRYPT_CONST_2
return ret
|