-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdiffecientwo.py
96 lines (82 loc) · 3.15 KB
/
diffecientwo.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import math
import mmh3
class BloomFilter:
def __init__(self, m, k, hash_func=mmh3.hash):
self.__m = m
self.__k = k
self.__i = 0
self.__digests = set()
self.hash = hash_func
def security(self):
false_positive = pow(
1 - pow(math.e, -self.__k * self.__i / self.__m), self.__k)
try:
return int(1 / false_positive).bit_length()
except (ZeroDivisionError, OverflowError):
return float('inf')
def _add(self, item):
self.__i += 1
for i in range(self.__k):
self.__digests.add(self.hash(item, i) % self.__m)
def check(self, item):
return all(self.hash(item, i) % self.__m in self.__digests
for i in range(self.__k))
def num_passwords(self):
return self.__i
def memory_consumption(self):
return 4 * len(self.__digests)
class SocialCache(BloomFilter):
def __init__(self, m, k, post_size=32, num_posts=16, hash_func=mmh3.hash):
super().__init__(m, k, hash_func)
self.post_size = post_size
self._num_posts = num_posts
def add_post(self, post: bytes):
if len(post) > self.post_size:
print("Post too long")
elif self._num_posts <= 0:
print("User exceeded number of allowed posts")
else:
self._add(post)
self._num_posts -= 1
print("Added successfully! Posts remaining", self._num_posts)
def find_post(self, post: bytes):
if self.check(post):
print("Found the post in our DB")
else:
print("Could not find post in our DB")
def grant_free_api(self):
if self.check(b"#SEKAICTF #DEUTERIUM #DIFFECIENTWO #CRYPTO"):
from flag import flag
print(flag)
else:
print("Sorry, you dont seem to have posted about us")
BANNER = r"""
____ ____ ____ ____ ____ ___ ____ ____ _ _ ____ _ _ _____
( _ \(_ _)( ___)( ___)( ___)/ __)(_ _)( ___)( \( )(_ _)( \/\/ )( _ )
)(_) )_)(_ )__) )__) )__)( (__ _)(_ )__) ) ( )( ) ( )(_)(
(____/(____)(__) (__) (____)\___)(____)(____)(_)\_) (__) (__/\__)(_____)
Welcome to diffecientwo caching database API for tracking and storing
content across social media. We have repurposed our security product as
saving the admin key was probably not the best idea, but we have decided
to change our policies and to achieve better marketing, we are offering
free API KEY to customers sharing #SEKAICTF #DEUTERIUM #DIFFECIENTWO #CRYPTO
on LonelyFans (our premium business partner).
"""
print(BANNER)
LONELY_FANS = SocialCache(2**32 - 5, 64, 32, 22)
while True:
try:
option = int(input("Enter API option:\n"))
if option == 1:
post = bytes.fromhex(input("Enter post in hex\n"))
LONELY_FANS.find_post(post)
elif option == 2:
post = bytes.fromhex(input("Enter post in hex\n"))
LONELY_FANS.add_post(post)
elif option == 3:
LONELY_FANS.grant_free_api()
elif option == 4:
exit(0)
except BaseException:
print("Something wrong happened")
exit(1)