cryptosploit_modules.symmetric.atbash

View Source
 0from cryptosploit.cprint import Printer
 1from cryptosploit_modules import BaseModule
 2from os.path import isfile
 3
 4
 5class Atbash(BaseModule):
 6    def __init__(self):
 7        super().__init__()
 8        self.env.check_var = self.check_var
 9
10    def check_var(self, name, value):
11        match name:
12            case "mode":
13                if value not in ("decrypt", "encrypt"):
14                    return False, "No such mode!"
15        return True, ""
16
17    def encrypt(self):
18        result = ""
19        alphabet = self.env.get_var("alphabet").value.upper()
20        d = dict(zip(alphabet, alphabet[::-1]))
21        inp = self.env.get_var("input").value
22        if isfile(inp):
23            with open(inp) as f:
24                inp = f.read()
25        for ind, char in enumerate(inp.upper()):
26            if char in d:
27                res_char = d[char]
28                result += res_char if inp[ind].isupper() else res_char.lower()
29            else:
30                result += char
31        return result
32
33    def decrypt(self):
34        return self.encrypt()
35
36    def run(self):
37        func = getattr(self, self.env.get_var("mode").value)
38        result = func()
39        if result:
40            Printer.positive("Result:\n" + result)
41        else:
42            Printer.negative("Result:\nNone")
43
44
45module = Atbash
View Source
 6class Atbash(BaseModule):
 7    def __init__(self):
 8        super().__init__()
 9        self.env.check_var = self.check_var
10
11    def check_var(self, name, value):
12        match name:
13            case "mode":
14                if value not in ("decrypt", "encrypt"):
15                    return False, "No such mode!"
16        return True, ""
17
18    def encrypt(self):
19        result = ""
20        alphabet = self.env.get_var("alphabet").value.upper()
21        d = dict(zip(alphabet, alphabet[::-1]))
22        inp = self.env.get_var("input").value
23        if isfile(inp):
24            with open(inp) as f:
25                inp = f.read()
26        for ind, char in enumerate(inp.upper()):
27            if char in d:
28                res_char = d[char]
29                result += res_char if inp[ind].isupper() else res_char.lower()
30            else:
31                result += char
32        return result
33
34    def decrypt(self):
35        return self.encrypt()
36
37    def run(self):
38        func = getattr(self, self.env.get_var("mode").value)
39        result = func()
40        if result:
41            Printer.positive("Result:\n" + result)
42        else:
43            Printer.negative("Result:\nNone")
#   Atbash()
View Source
7    def __init__(self):
8        super().__init__()
9        self.env.check_var = self.check_var
#   def check_var(self, name, value):
View Source
11    def check_var(self, name, value):
12        match name:
13            case "mode":
14                if value not in ("decrypt", "encrypt"):
15                    return False, "No such mode!"
16        return True, ""
#   def encrypt(self):
View Source
18    def encrypt(self):
19        result = ""
20        alphabet = self.env.get_var("alphabet").value.upper()
21        d = dict(zip(alphabet, alphabet[::-1]))
22        inp = self.env.get_var("input").value
23        if isfile(inp):
24            with open(inp) as f:
25                inp = f.read()
26        for ind, char in enumerate(inp.upper()):
27            if char in d:
28                res_char = d[char]
29                result += res_char if inp[ind].isupper() else res_char.lower()
30            else:
31                result += char
32        return result
#   def decrypt(self):
View Source
34    def decrypt(self):
35        return self.encrypt()
#   def run(self):
View Source
37    def run(self):
38        func = getattr(self, self.env.get_var("mode").value)
39        result = func()
40        if result:
41            Printer.positive("Result:\n" + result)
42        else:
43            Printer.negative("Result:\nNone")

Required to be overridden in the child class. Function called by the user

View Source
 6class Atbash(BaseModule):
 7    def __init__(self):
 8        super().__init__()
 9        self.env.check_var = self.check_var
10
11    def check_var(self, name, value):
12        match name:
13            case "mode":
14                if value not in ("decrypt", "encrypt"):
15                    return False, "No such mode!"
16        return True, ""
17
18    def encrypt(self):
19        result = ""
20        alphabet = self.env.get_var("alphabet").value.upper()
21        d = dict(zip(alphabet, alphabet[::-1]))
22        inp = self.env.get_var("input").value
23        if isfile(inp):
24            with open(inp) as f:
25                inp = f.read()
26        for ind, char in enumerate(inp.upper()):
27            if char in d:
28                res_char = d[char]
29                result += res_char if inp[ind].isupper() else res_char.lower()
30            else:
31                result += char
32        return result
33
34    def decrypt(self):
35        return self.encrypt()
36
37    def run(self):
38        func = getattr(self, self.env.get_var("mode").value)
39        result = func()
40        if result:
41            Printer.positive("Result:\n" + result)
42        else:
43            Printer.negative("Result:\nNone")
#   module()
View Source
7    def __init__(self):
8        super().__init__()
9        self.env.check_var = self.check_var
#   def check_var(self, name, value):
View Source
11    def check_var(self, name, value):
12        match name:
13            case "mode":
14                if value not in ("decrypt", "encrypt"):
15                    return False, "No such mode!"
16        return True, ""
#   def encrypt(self):
View Source
18    def encrypt(self):
19        result = ""
20        alphabet = self.env.get_var("alphabet").value.upper()
21        d = dict(zip(alphabet, alphabet[::-1]))
22        inp = self.env.get_var("input").value
23        if isfile(inp):
24            with open(inp) as f:
25                inp = f.read()
26        for ind, char in enumerate(inp.upper()):
27            if char in d:
28                res_char = d[char]
29                result += res_char if inp[ind].isupper() else res_char.lower()
30            else:
31                result += char
32        return result
#   def decrypt(self):
View Source
34    def decrypt(self):
35        return self.encrypt()
#   def run(self):
View Source
37    def run(self):
38        func = getattr(self, self.env.get_var("mode").value)
39        result = func()
40        if result:
41            Printer.positive("Result:\n" + result)
42        else:
43            Printer.negative("Result:\nNone")

Required to be overridden in the child class. Function called by the user