Skip to content

Commit

Permalink
commenting out main
Browse files Browse the repository at this point in the history
  • Loading branch information
marcsantiago committed Feb 28, 2017
1 parent 2768f32 commit f2276e7
Show file tree
Hide file tree
Showing 11 changed files with 45,927 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Cryptokit/CaesarCipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def c_encipher(plain_text, key, file_mode=False):
translated.append(ch)

answer = input("Write data to file? [y], [n]\n")

if answer.lower() in ["yes", "y"]:
with open("enciphered_caesar.txt", 'w') as data:
data.write("".join(translated))
Expand Down Expand Up @@ -152,6 +152,6 @@ def brute_force_decrypt(cypher_text, file_mode=False):
translated.append(chr(num))
else:
translated.append(ch)

if detectEnglish.isEnglish("".join(translated)):
return "Key: %s String: %s" % (abs(key), "".join(translated))
8 changes: 4 additions & 4 deletions Cryptokit/HideMessageInImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def hide_or_show_message():
plaintext = enterbox("Enter a message you would like to hide in an image.")
im = Image.fromstring('L', (1, len(plaintext)), plaintext)
filename = enterbox("Give your image a name.")

if ".png" in filename:
filename = filename.replace(".png", "")
im.save(filename + ".png", format("PNG"))

elif answer == "Decrypt":
image_file = fileopenbox("Please pick an image file that you would like to decrypt.", filetypes=["*.png"])
my_image = Image.open(image_file)
pix = my_image.getdata()

for i in list(pix):
temp_data.append(i)

return msgbox("".join([chr(i) for i in temp]))
return msgbox("".join([chr(i) for i in temp_data]))
37 changes: 18 additions & 19 deletions Cryptokit/OneTimePadEncryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ def _key_generator(time):
the length of the provided string."""
print("Generating Key Please Wait...")
filename = "_".join(["key", time])
key_list = []
key_list = []
for i in range(32):
key_list.append(choice(ascii_letters))

with open(filename + ".dat", 'w') as data:
data.write("".join(key_list))
return _string_converter("".join(key_list))

def _encrypt_key_file(zip_password, time):
"""Encrypts the key.dat file with a zip encryption using pyminizip.
For more instructions regarding pyminizip you can visit pypi.python.org
and search for the module or google it."""

filename = "_".join(["key", time])
compress(filename + ".dat", filename + ".zip", zip_password, int(9))
remove(filename + ".dat")

def _unzip_file(zip_file, zip_password):
"""Unzips key.zip file using a supplied password."""

if version_info >= (3, 0):
ZipFile(zip_file).extractall(pwd=str.encode(zip_password))
print("File unzipped.")
Expand All @@ -88,9 +88,9 @@ def decrypt_data(encrypted_string, key, string_file_mode=False, key_file_mode=Fa
string or can the key and encrypted string a as file and decrypts
the string using the provided string. NOTE** In order to use the the key.dat file
you must first also be able to unzip it using a password."""

print("Starting Decryption...")

if key_file_mode:
if ".zip" in key:
zf = ZipFile(key)
Expand All @@ -103,7 +103,7 @@ def decrypt_data(encrypted_string, key, string_file_mode=False, key_file_mode=Fa
except:
print("Key.zip is encrypted!\n")
_unzip_file(key, input("Please enter the password to unzip the key file and try again.\n"))

else:
my_key = key
with open(my_key, 'r') as key_data:
Expand Down Expand Up @@ -142,26 +142,26 @@ def decrypt_data(encrypted_string, key, string_file_mode=False, key_file_mode=Fa
def encrypt_data(plain_text, string_file_mode=False):
"""Method that takes either the key or plaintext as a
string or file. The key is randomly generated for you!"""

print("Starting Encryption...")

timestamp = str(datetime.now().strftime("%y%m%d_%H%M%S"))
filename = "_".join(["encrypted_message", timestamp])

if string_file_mode:
with open(plain_text) as plaintext_data:
file_data = str(plaintext_data.read())
string_list = _string_converter(file_data)
else:
string_list = _string_converter(plain_text)

key_list = _key_generator(timestamp)[2:]

print("Encrypting file...please wait, this may take a while depending on file size.")
encrypted_list = []
for j in range(2, len(string_list)):
index = j % len(key_list)
encrypted_list.append(int(string_list[j]) ^ int(key_list[index]))
encrypted_list.append(int(string_list[j]) ^ int(key_list[index]))

with open(filename + ".txt", 'w') as message:
message.write( "0b" + "".join((str(i) for i in encrypted_list)))
Expand All @@ -171,10 +171,9 @@ def encrypt_data(plain_text, string_file_mode=False):

return "0b" + "".join((str(i) for i in encrypted_list))

def main():
#encrypt_data("test.txt", string_file_mode=True)
decrypt_data("encrypted_message_150412_105314.txt", "key_150412_105314.dat", string_file_mode=True, key_file_mode=True)

if __name__ in '__main__':
main()

# def main():
# #encrypt_data("test.txt", string_file_mode=True)
# decrypt_data("encrypted_message_150412_105314.txt", "key_150412_105314.dat", string_file_mode=True, key_file_mode=True)
#
# if __name__ in '__main__':
# main()
157 changes: 157 additions & 0 deletions build/lib/Cryptokit/CaesarCipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#!/usr/bin/env python
"""This module is designed to provide users Caesar Cipher tools."""
from __future__ import division, absolute_import, print_function, unicode_literals
__author__ = 'marcsantiago'

from helper_files import detectEnglish

try:
from future_builtins import *
except ImportError:
pass

try:
input = raw_input
range = xrange
except NameError:
pass

def c_encipher(plain_text, key, file_mode=False):
"""The encipher module takes plain text as enter a passed string
argument or a basic .txt file. A key must also be provide. Since, this
if a Caesar Cipher the key that is provide must be in the range of 1 through 26"""
try:
assert type(key) == type(int())
except AssertionError as e:
print("Entered key must be a an integer and a string: %s" % str(e))

try:
assert key > 0 and key < 27
except:
print("Key must be greater than 0 and less than 27.")

translated = []

if file_mode:
with open(plain_text, 'r') as in_data:
plain = in_data.read()
else:
plain = plain_text

for ch in plain:
if ch.isalpha():
num = ord(ch)
num += key

if ch.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26

elif ch.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26

translated.append(chr(num))
else:
translated.append(ch)

answer = input("Write data to file? [y], [n]\n")

if answer.lower() in ["yes", "y"]:
with open("enciphered_caesar.txt", 'w') as data:
data.write("".join(translated))
return "".join(translated)
else:
return "".join(translated)

def c_decipher(cypher_text, key, file_mode=False):
"""The decipher module takes cypher text as enter a passed string
argument or a basic .txt file. A key must also be provide. Since, this
if a Caesar Cipher the key that is provide must be in the range of 1 through 26"""
try:
assert type(key) == type(int())
except AssertionError as e:
print("Entered key must be a an integer and a string: %s" % str(e))

try:
assert 0 < key < 27
except:
print("Key must be greater than 0 and less than 27.")

key = -key

translated = []

if file_mode:
with open(cypher_text, 'r') as in_data:
plain = in_data.read()
else:
plain = cypher_text

for ch in plain:
if ch.isalpha():
num = ord(ch)
num += key

if ch.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif ch.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26

translated.append(chr(num))
else:
translated.append(ch)

answer = input("Write data to file? [y], [n]\n")
if answer.lower() in ["yes", "y"]:
with open("deciphered_caesar.txt", 'w') as data:
data.write("".join(translated))
return "".join(translated)
else:
return "".join(translated)

def brute_force_decrypt(cypher_text, file_mode=False):
"""This method trys all the possible keys on a cyphered text and returns the
key and plain text string. It does this using the imported dictionary module, which
is a modified version of http://inventwithpython.com/hacking (BSD Licensed)'s dictionary module.
If an English plaintext is not found all 26 garbage keys will be printed for you to double check."""
if file_mode:
with open(cypher_text, 'r') as in_data:
cypher = in_data.read()
else:
cypher = cypher_text

for key in range(1, 27):
key = -key
translated = []
for ch in cypher:
if ch.isalpha():
num = ord(ch)
num += key
if ch.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif ch.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26

translated.append(chr(num))
else:
translated.append(ch)

if detectEnglish.isEnglish("".join(translated)):
return "Key: %s String: %s" % (abs(key), "".join(translated))
45 changes: 45 additions & 0 deletions build/lib/Cryptokit/HideMessageInImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
from __future__ import division, absolute_import, print_function, unicode_literals
# This is module is designed to hide a string message inside of an image. Note, This
# is just for fun and applies no real encryption. This is more of a way to obscure
# one's message inside of a png file
__author__ = 'marcsantiago'

try:
from PIL import Image
except ImportError:
print("This module requires the PIL module.")
print("To install the PIL module on unix or linux,")
print("type [pip install Pillow] terminal.")
print("If using python3 please use [pip3 install Pillow].")

try:
from easygui import buttonbox, enterbox, msgbox, fileopenbox
except ImportError:
print("This module requires the easygui module.")
print("To install the easygui module on unix or linux,")
print("type [pip install easygui] terminal.")
print("If using python3 please use [pip3 install easygui].")

def hide_or_show_message():
"""This method ask the user whether they want to encrypt a string or decrypt a *.png file."""
temp_data = []
answer = buttonbox("What would you like to do, encrypt a message or decrypt the image?", choices=["Encrypt", "Decrypt"])
if answer == "Encrypt":
plaintext = enterbox("Enter a message you would like to hide in an image.")
im = Image.fromstring('L', (1, len(plaintext)), plaintext)
filename = enterbox("Give your image a name.")

if ".png" in filename:
filename = filename.replace(".png", "")
im.save(filename + ".png", format("PNG"))

elif answer == "Decrypt":
image_file = fileopenbox("Please pick an image file that you would like to decrypt.", filetypes=["*.png"])
my_image = Image.open(image_file)
pix = my_image.getdata()

for i in list(pix):
temp_data.append(i)

return msgbox("".join([chr(i) for i in temp_data]))
Loading

0 comments on commit f2276e7

Please sign in to comment.