Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
aloner-pro committed Dec 29, 2020
2 parents e9ac6a5 + d4a1b18 commit a30eac8
Show file tree
Hide file tree
Showing 13 changed files with 939 additions and 0 deletions.
Binary file added New Folder (2)/COMPUTER_PROJECT.docx
Binary file not shown.
21 changes: 21 additions & 0 deletions New Folder (2)/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Sohel Ahmed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions New Folder (2)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Steno :loop:
## Ultimate Stenography software:superhero:
The do all stenography application.:grin:<br>
**Formats Supported-**
- Images
- Audio
- Text
- ~~Video~~ _To be supported in future version_
>This is an important application especially in today's world.<br>
> We need hide the messages rather than only encrypting them.
---
### Stenography is not Cryptography ! :confused:
If you are getting confused between _Stenography_ & _Cryptography_. Then see this -
#### Cryptography
**If** `you = wms` **then** `Qcaapgrw gq gknmprylr` **= ?**<br>
_Can you guess the answer?_<br>
Here we have `key = -2` i.e. if we go 2 alphabets behind `y` you get
`w` and similarly if you go 2 alphabets behind `o` we get `m` and similarly 2 alphabets behind `u` gives us `s`. Therefore `you = wms`. <br>
So now you may have got the answer which is `Security is important`.
> Note: The cryptography algorithms are much advanced now.
#### Stenography
So now that you know what is cryptography so lets know what is _Stenography_.<br>
**If** `____=____` **then** `______=______` **?**<br>
_Confused ?_<br>
Here you won't be able to even sense the presence of data. Leave alone knowing what
is the data. That's why it is called hiding data in plain sight. There are some applications which
may detect the presence of hidden data. CIA obviously has it <emoji><br>
Generally at professional level the data hidden is encrypted first. So _stenography_ and _cryptography_ are not
mutually exclusive to each other.
>Knowledge fact: Jeff Bezos's mobile was hacked by hiding malicious code in a media
>file which on getting downloaded sent the host device's control to the hacker.
---
Binary file added New Folder (2)/SNOW.EXE
Binary file not shown.
Binary file added New Folder (2)/data.db
Binary file not shown.
Binary file added New Folder (2)/images/noshow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New Folder (2)/images/show.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
570 changes: 570 additions & 0 deletions New Folder (2)/main.txt

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions New Folder (2)/sten/audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# this module comes with standard python installation
import wave
"""
*<[only supports wave files]>*
This module helps us in performing audio stenography
on wave files as they are lossless audio files.
link - https://tinyurl.com/yy3sx6ku
"""


def embed(infile: str, message: str, outfile: str):
# TODO add password functionality preferably using encryption
"""This takes your message and hides it in infile and saves it in outfile"""
song = wave.open(infile, mode='rb')
# Read frames and convert to byte array
frame_bytes = bytearray(list(song.readframes(song.getnframes())))

# Append dummy data to fill out rest of the bytes. Receiver shall detect and remove these characters.
message = message + int((len(frame_bytes) - (len(message) * 8 * 8)) / 8) * '#'
# Convert text to bit array
bits = list(map(int, ''.join([bin(ord(i)).lstrip('0b').rjust(8, '0') for i in message])))

# Replace LSB of each byte of the audio data by one bit from the text bit array
for i, bit in enumerate(bits):
frame_bytes[i] = (frame_bytes[i] & 254) | bit
frame_modified = bytes(frame_bytes)

# Write bytes to a new wave audio file
with wave.open(outfile, 'wb') as fd:
fd.setparams(song.getparams())
fd.writeframes(frame_modified)
song.close()


def extract(file: str):
"""This function takes the filepath and decodes the hidden data and returns it"""
song = wave.open(file, mode='rb')
# Convert audio to byte array
frame_bytes = bytearray(list(song.readframes(song.getnframes())))
# Extract the LSB of each byte
extracted = [frame_bytes[i] & 1 for i in range(len(frame_bytes))]
# Convert byte array back to string
message = "".join(chr(int("".join(map(str, extracted[i:i+8])), 2)) for i in range(0, len(extracted), 8))
# Cut off at the filler characters
decoded = message.split("###")[0]
song.close()
return decoded
45 changes: 45 additions & 0 deletions New Folder (2)/sten/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import platform
import psutil
import sqlite3 as db
from datetime import date

connect = db.connect('data.db')
cursor = connect.cursor()
info = platform.system() + ' ' + str(round(psutil.virtual_memory().total / (1024.0 ** 3))) + "GB"


def new(name: str, user: str, passwd: str):
cursor.execute("insert into initial values (?, ?, ?, ?)", (name, user, passwd, date.today()))
connect.commit()


def format_txt(file: str, passwd: str):
cursor.execute("insert into user values (?, ?, ?, ?, ?)", ('text', date.today(), file, passwd, info))
connect.commit()


def format_oth(types: str, file: str):
st = "insert into user('FORMAT', 'TIME_STAMP', 'FILE_PATH', 'OS_RAM') VALUES(?, ?, ?, ?)", (
types, date.today(), file, info)
cursor.execute(st)
connect.commit()


def main_work(username: str, passwd: str, file: str):
data = cursor.execute("SELECT NAME,PASSWORD FROM initial WHERE USERNAME=?", (username,)).fetchall()
if not data:
return 'No Admin Account',
else:
for i in range(len(data)):
if passwd == data[i][1]:
data2 = cursor.execute("SELECT PASSWORD FROM user WHERE FILE_PATH=?", (file,)).fetchone()
if not data2:
return 'No such file',
else:
return data[i][0], data2
else:
return 'Wrong Password',


def close():
connect.close()
53 changes: 53 additions & 0 deletions New Folder (2)/sten/hover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from tkinter import *
"""
This module helps us to have a hovering effect on any
widget in tkinter. It helps in giving the user info about
the widget. Especially used to hover over buttons and giving
info about their usage.
link - https://cutt.ly/fhzdiqy
"""


class ToolTip(object):

def __init__(self, widget):
self.widget = widget
self.tipwindow = None
self.id = None
self.x = self.y = 0

def showtip(self, text):
"""Display text in tooltip window"""
self.text = text
if self.tipwindow or not self.text:
return
x, y, cx, cy = self.widget.bbox("insert")
x = x + self.widget.winfo_rootx() + 57
y = y + cy + self.widget.winfo_rooty() + 27
self.tipwindow = tw = Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x, y))
label = Label(tw, text=self.text, justify=LEFT,
background="#ffffe0", relief=SOLID, borderwidth=1,
font=("tahoma", "8", "normal"))
label.pack(ipadx=1)

def hidetip(self):
tw = self.tipwindow
self.tipwindow = None
if tw:
tw.destroy()


def CreateToolTip(widget, text):
"""Main function which is called in programs"""
toolTip = ToolTip(widget)

def enter(event):
toolTip.showtip(text)

def leave(event):
toolTip.hidetip()

widget.bind('<Enter>', enter)
widget.bind('<Leave>', leave)
134 changes: 134 additions & 0 deletions New Folder (2)/sten/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@


# Convert encoding data into 8-bit binary
# form using ASCII value of characters
def genData(data):

# list of binary codes
# of given data
newd = []

for i in data:
newd.append(format(ord(i), '08b'))
return newd

# Pixels are modified according to the
# 8-bit binary data and finally returned
def modPix(pix, data):

datalist = genData(data)
lendata = len(datalist)
imdata = iter(pix)

for i in range(lendata):

# Extracting 3 pixels at a time
pix = [value for value in imdata.__next__()[:3] +
imdata.__next__()[:3] +
imdata.__next__()[:3]]

# Pixel value should be made
# odd for 1 and even for 0
for j in range(0, 8):
if (datalist[i][j] == '0' and pix[j]% 2 != 0):
pix[j] -= 1

elif (datalist[i][j] == '1' and pix[j] % 2 == 0):
if(pix[j] != 0):
pix[j] -= 1
else:
pix[j] += 1
# pix[j] -= 1

# Eighth pixel of every set tells
# whether to stop ot read further.
# 0 means keep reading; 1 means thec
# message is over.
if (i == lendata - 1):
if (pix[-1] % 2 == 0):
if(pix[-1] != 0):
pix[-1] -= 1
else:
pix[-1] += 1

else:
if (pix[-1] % 2 != 0):
pix[-1] -= 1

pix = tuple(pix)
yield pix[0:3]
yield pix[3:6]
yield pix[6:9]

def encode_enc(newimg, data):
w = newimg.size[0]
(x, y) = (0, 0)

for pixel in modPix(newimg.getdata(), data):

# Putting modified pixels in the new image
newimg.putpixel((x, y), pixel)
if (x == w - 1):
x = 0
y += 1
else:
x += 1

# Encode data into image
def encode():
img = input("Enter image name(with extension) : ")
image = Image.open(img, 'r')

data = input("Enter data to be encoded : ")
if (len(data) == 0):
raise ValueError('Data is empty')

newimg = image.copy()
encode_enc(newimg, data)

new_img_name = input("Enter the name of new image(with extension) : ")
newimg.save(new_img_name, str(new_img_name.split(".")[1].upper()))

# Decode the data in the image
def decode():
img = input("Enter image name(with extension) : ")
image = Image.open(img, 'r')

data = ''
imgdata = iter(image.getdata())

while (True):
pixels = [value for value in imgdata.__next__()[:3] +
imgdata.__next__()[:3] +
imgdata.__next__()[:3]]

# string of binary data
binstr = ''

for i in pixels[:8]:
if (i % 2 == 0):
binstr += '0'
else:
binstr += '1'

data += chr(int(binstr, 2))
if (pixels[-1] % 2 != 0):
return data

# Main Function
def main():
a = int(input(":: Welcome to Steganography ::\n"
"1. Encode\n2. Decode\n"))
if (a == 1):
encode()

elif (a == 2):
print("Decoded Word : " + decode())
else:
raise Exception("Enter correct input")

# Driver Code
if __name__ == '__main__' :

# Calling main function
main()
37 changes: 37 additions & 0 deletions New Folder (2)/sten/text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# these modules come with standard python installation
import os
import subprocess
__author__ = "Sohel Ahmed"
'''
Module text.py for performing text stenography using SNOW
link - http://darkside.com.au/snow/ -- here you will get to
know about SNOW and also download it. This mainly hides your
data inside spaces and tabs & also encrypts it.
'''


def size(file: str):
"""Used to know how much data can be hidden in the file returns it in bytes"""
cmd = subprocess.Popen(['snow', '-S', file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = cmd.communicate()
return str(stdout, 'utf-8').split()[-2]


def encode(passwd: str, infile: str, outfile: str, file: str = None, message: str = None):
"""This is used to encode data in the file with password. Returns nothing"""
if message is not None:
"""If the data is a message it encodes it inside the contents of infile and saves it in outfile"""
command = 'snow -C -Q -p "{}" -m "{}" {} {}'.format(passwd, message, infile, outfile)
os.system('cmd /c' + command)
elif file is not None:
"""If the data is a file it encodes it in infile and saves it as outfile"""
command = 'snow -C -Q -p "{}" -f {} {} {}'.format(passwd, file, infile, outfile)
os.system('cmd /c' + command)


def decode(passwd: str, file: str):
"""Decodes the data hidden in the file. Returns the data in readable
form if password is correct else in encrypted form."""
cmd = subprocess.Popen(['snow', '-C', '-p', passwd, file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = cmd.communicate()
return str(stdout, 'utf-8')

0 comments on commit a30eac8

Please sign in to comment.