-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·42 lines (34 loc) · 1.1 KB
/
server.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
#!/usr/bin/env python3
import sys
import params
from protocol import IO, NoEncryption, RSAEncryption
def select_cipher():
print('[*] Please, select encryption mode:')
print('[0] No encryption')
print('[1] RSA')
choice = int(input())
if choice == 0:
return NoEncryption()
if choice == 1:
io = IO(sys.stdin.buffer, sys.stdout.buffer)
return RSAEncryption(io, params)
raise Exception('encryption mode is not implemented')
def main(flag):
cipher = select_cipher()
print(cipher.encrypt('[*] Please, input your flag:'))
attempt = cipher.decrypt(input()).strip()
print(cipher.encrypt('[*] Checking %s ...' % attempt))
if len(attempt) != len(flag):
print(cipher.encrypt('[-] Incorrect length :('))
elif attempt != flag:
print(cipher.encrypt('[-] Wrong :('))
else:
print(cipher.encrypt('[+] Correct :)'))
print(cipher.encrypt('[*] Bye!'))
if __name__ == '__main__':
with open('flag.txt', 'r') as file:
flag = file.read().strip()
try:
main(flag)
except Exception as e:
print('[-] %s' % e)