[file]: Move utils file to dir
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
from PIL import Image, ImageDraw # Подключим необходимые библиотеки.
|
||||
|
||||
|
||||
def write(ifile, ofile, text):
|
||||
secret = ''
|
||||
|
||||
for char in text:
|
||||
ccode = str(bin(ord(char)))[2:]
|
||||
while len(ccode) < 16:
|
||||
ccode = '0' + ccode
|
||||
secret += ccode
|
||||
secret += '0000000000000000'
|
||||
|
||||
image = Image.open(ifile)
|
||||
draw = ImageDraw.Draw(image)
|
||||
width, height = image.size
|
||||
pix = image.load()
|
||||
|
||||
dindex = 0
|
||||
|
||||
for w in range(width):
|
||||
for h in range(height):
|
||||
|
||||
red = pix[w, h][0]
|
||||
green = pix[w, h][1]
|
||||
blue = pix[w, h][2]
|
||||
|
||||
try:
|
||||
if blue % 2 != int(secret[dindex]):
|
||||
blue += 1
|
||||
if blue > 255:
|
||||
blue -= 2
|
||||
dindex += 1
|
||||
except IndexError:
|
||||
if blue % 2 != 0:
|
||||
blue += 1
|
||||
if blue > 255:
|
||||
blue -= 2
|
||||
|
||||
draw.point((w, h), (red, green, blue))
|
||||
fformat = 'PNG'
|
||||
|
||||
if ofile[-3].endswith('png'):
|
||||
fformat = 'PNG'
|
||||
elif ofile[-3].endswith('jpg'):
|
||||
fformat = 'JPEG'
|
||||
|
||||
image.save(ofile, fformat)
|
||||
|
||||
|
||||
|
||||
def read(file):
|
||||
image = Image.open(file)
|
||||
width = image.size[0]
|
||||
height = image.size[1]
|
||||
pix = image.load()
|
||||
|
||||
solve = ''
|
||||
out = ''
|
||||
|
||||
for w in range(width):
|
||||
for h in range(height):
|
||||
blue = pix[w, h][2]
|
||||
solve += str(blue % 2)
|
||||
|
||||
solve = list(solve)
|
||||
|
||||
i = 0
|
||||
while len(solve) >= 16:
|
||||
char = ''.join(solve[:16])
|
||||
char = int(char, 2)
|
||||
if char == 0:
|
||||
break
|
||||
out += chr(char)
|
||||
|
||||
del solve[:16]
|
||||
|
||||
i += 1
|
||||
|
||||
return out
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
choose = input('Прочесть или записать? [r/w] ')
|
||||
|
||||
if choose == 'w':
|
||||
text = input('Введи текст для зашифроки: ')
|
||||
write('unknown.png', 'secret.png', text)
|
||||
|
||||
elif choose == 'r':
|
||||
print(read('secret.png'))
|
||||
@@ -0,0 +1,49 @@
|
||||
def char_encode(text, key):
|
||||
itext = ''
|
||||
ikey = ''
|
||||
out = ''
|
||||
|
||||
for char in text:
|
||||
char = str(bin(ord(char)))
|
||||
char = char.replace('0b', '')
|
||||
while len(char) < 16:
|
||||
char = '0' + char
|
||||
itext += char
|
||||
|
||||
for char in key:
|
||||
char = str(bin(ord(char)))
|
||||
char = char.replace('0b', '')
|
||||
while len(char) < 16:
|
||||
char = '0' + char
|
||||
ikey += char
|
||||
|
||||
if len(itext) > len(ikey):
|
||||
tmp = ikey
|
||||
ikey = tmp * int(len(itext) / len(tmp))
|
||||
ikey += tmp[:(len(itext) % len(tmp))]
|
||||
|
||||
for i in range(len(itext)):
|
||||
a = itext[i]
|
||||
b = ikey[i]
|
||||
|
||||
if a == b:
|
||||
out += '0'
|
||||
else:
|
||||
out += '1'
|
||||
tmp = list(out)
|
||||
out = ''
|
||||
|
||||
while len(tmp) >= 16:
|
||||
char = ''.join(tmp[:16])
|
||||
char = int(char, 2)
|
||||
out += chr(char)
|
||||
|
||||
del tmp[:16]
|
||||
|
||||
return out
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cat = char_encode('123123', 'кот')
|
||||
print(cat)
|
||||
print(char_encode(cat, 'кот'))
|
||||
@@ -0,0 +1,16 @@
|
||||
from random import choice
|
||||
|
||||
from discord import Color
|
||||
|
||||
light_colors = [
|
||||
Color(0xaaffaa),
|
||||
Color(0xF9FFAA),
|
||||
Color(0xFFAAAA),
|
||||
Color(0xFFCCAA),
|
||||
Color(0xAAFFE3),
|
||||
Color(0xAAB0FF),
|
||||
Color(0xFFAAF7)
|
||||
]
|
||||
|
||||
def choise_light_color(): return choice(light_colors)
|
||||
|
||||
Reference in New Issue
Block a user