Skip to content

Commit 251525c

Browse files
committed
Piencrypt Test and example
1 parent 3d430d1 commit 251525c

5 files changed

Lines changed: 109 additions & 43 deletions

File tree

Test/main.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

Test/pie_clone.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class PiEncrypt:
2+
3+
def __init__(self, loc):
4+
self.loc = loc
5+
6+
# save the data of the picture as bytes
7+
def get_data(self):
8+
with open(self.loc , 'rb') as f, open('binary.txt', 'wb') as b:
9+
r = f.read()
10+
b.write(r)
11+
12+
# hides the disired data into the picture
13+
def hide_data(self, data):
14+
self.data = data
15+
with open(self.loc, 'ab') as f:
16+
f.write(bytes("HERE" + self.data , encoding="ascii"))
17+
18+
# read the hidden data from the picture
19+
def read_data(self):
20+
with open(self.loc, 'rb') as f:
21+
content = f.read()
22+
list = content.split(b'HERE')
23+
# print(f.read())
24+
return list[1].decode("utf-8")
25+
26+
# revert the picture from the backup bytes file
27+
def revert(self):
28+
with open('binary.txt', 'rb') as f, open(self.loc, 'wb') as e:
29+
r = f.read()
30+
e.write(r)
31+
32+
if __name__ == '__main__':
33+
34+
p = PiEncrypt('pic.png')
35+
p.get_data()
36+
p.hide_data("Hello my name is Sid")
37+
r = p.read_data()
38+
p.revert()
39+
print(r)

Test/pie_test.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from pie_clone import PiEncrypt
2+
import random
3+
import unittest
4+
5+
6+
Texts = ['Hi', 'Solo', 'Sid', 'Test', 'Lily', 'Python', 'Throttlerz', 'Password', 'Good Morning', 'Good Evening']
7+
8+
class TestClac(unittest.TestCase):
9+
def test_quantity(self):
10+
for i in range(800):
11+
data = []
12+
for i in range(5):
13+
r = random.choice(Texts)
14+
data.append(r)
15+
input = ", ".join(data)
16+
try:
17+
r = PiEncrypt('pic.png')
18+
r.get_data()
19+
r.hide_data(input)
20+
output = r.read_data()
21+
r.revert()
22+
except Exception as e:
23+
raise ValueError(e)
24+
return output
25+
26+
def test_quality(self):
27+
28+
for i in range(10):
29+
data = []
30+
for i in range(5000):
31+
r = random.choice(Texts)
32+
data.append(r)
33+
34+
input = ", ".join(data)
35+
36+
try:
37+
r = PiEncrypt('pic.png')
38+
r.get_data()
39+
r.hide_data(input)
40+
output = r.read_data()
41+
r.revert()
42+
except Exception as e:
43+
raise ValueError(e)
44+
return output
45+
46+
47+
def infile_test():
48+
for i in range(10):
49+
data = []
50+
for i in range(5000):
51+
r = random.choice(Texts)
52+
data.append(r)
53+
54+
input = ", ".join(data)
55+
try:
56+
r = PiEncrypt('pic.png')
57+
r.get_data()
58+
r.hide_data(input)
59+
output = r.read_data()
60+
r.revert()
61+
print(output, end=r" %FINISHED% ")
62+
except Exception as e:
63+
raise ValueError(e)
64+
65+
if __name__ == "__main__":
66+
unittest.main()
67+
# infile_test()
68+
69+
70+

Test/piencrypt.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

Test/requirements.txt

1.17 KB
Binary file not shown.

0 commit comments

Comments
 (0)