-
Notifications
You must be signed in to change notification settings - Fork 0
/
verschluessler.py
56 lines (55 loc) · 1.64 KB
/
verschluessler.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
from random import randint
import csv
import ImageConvertor
import math
class Verschluessler():
keys = []
numbers = []
def __init__(self):
with open("NumbersForKeys.csv") as csvdatei:
csv_reader_object = csv.DictReader(csvdatei, delimiter=";")
for row in csv_reader_object:
self.keys.append(row["Key"])
self.numbers.append(row["Number"])
def readImage(self, imageToRead):
ImageConvertor.seek(in_file = imageToRead)
def writeImage(self, imageToPass):
ImageConvertor.hide(in_file = imageToPass)
def verschluesseln(self, string, key):
i = 0
result = ""
while i < len(string):
e = 0
if str(string[i]) != "\n":
while str(string[i]) != self.keys[e]:
e = e + 1
a = int(self.numbers[e])
b = key
c = str(math.sqrt(((a * a) + (b * b))))
result = result + str(c) + " "
if str(string[i]) == "\n":
result = result + "\n" + " "
i = i + 1
return result
def entschluesseln(self, string, key):
numbers = string.split(" ")
numbers = numbers[0:len(numbers) - 1]
result = ""
for elements in numbers:
if elements != "\n":
a = math.ceil(math.sqrt(((float(elements) * float(elements)) - (key * key))))
e = 0
while True:
if int(a) == int(self.numbers[e]):
break
if int(a + 1) == int(self.numbers[e]):
break
if int(a - 1) == int(self.numbers[e]):
break
e = e + 1
result += str(self.keys[e])
if elements == "\n":
result += "\n"
return result
def generateKey(self):
return randint(100, 999)