Improved code style.

This commit is contained in:
Cédric Bonhomme 2019-12-17 09:18:37 +01:00
parent 9b216d9d59
commit 71f6c08c28
No known key found for this signature in database
GPG key ID: A1CB94DE57B7A70D
19 changed files with 335 additions and 253 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from .parity import *
from .statistics import *

View file

@ -32,26 +32,28 @@ from PIL import Image
from collections import Counter
from collections import OrderedDict
def steganalyse(img):
"""
Steganlysis of the LSB technique.
"""
encoded = img.copy()
width, height = img.size
colours_counter = Counter() # type: typing.Counter[int]
colours_counter = Counter() # type: typing.Counter[int]
for row in range(height):
for col in range(width):
r, g, b = img.getpixel((col, row))
colours_counter[r] += 1
most_common = colours_counter.most_common(10)
dict_colours = OrderedDict(sorted(list(colours_counter.items()),
key=lambda t: t[1]))
dict_colours = OrderedDict(
sorted(list(colours_counter.items()), key=lambda t: t[1])
)
colours = 0 # type: float
colours = 0 # type: float
for colour in list(dict_colours.keys()):
colours += colour
colours = colours / len(dict_colours)
#return colours.most_common(10)
# return colours.most_common(10)
return list(dict_colours.keys())[:30], most_common