Skip to content

Commit

Permalink
Formatting, compile error fix and copyrighting
Browse files Browse the repository at this point in the history
  • Loading branch information
oskopek committed Jan 1, 2014
1 parent d8df46d commit 76e6fa5
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cryptoim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright 2013,2014 CryptoIM Development Team
Copyright 2013-2014 CryptoIM Development Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
20 changes: 10 additions & 10 deletions cryptoim/decryptor_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# encoding: utf-8

"""
Copyright 2013,2014 CryptoIM Development Team
Copyright 2013-2014 CryptoIM Development Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,10 +33,10 @@ def makeroundkey (key1, key2, strings):
strings[i] = int(strings[i].encode("hex"), 16)
#Puts strings into hex

for i in range (16):
if i %2 == 0:
for i in range(16):
if i % 2 == 0:
RoundKeys.append(key2^strings[i])
elif i %2 == 1:
elif i % 2 == 1:
RoundKeys.append(key1^strings[i])
else:
RoundKeys.append(key2^strings[i])
Expand All @@ -48,7 +48,7 @@ def makeroundkey (key1, key2, strings):
keys = []

ciphertext = ciphertext.split(",") #Converts string into list
for i in range (len (ciphertext)):
for i in range(len (ciphertext)):
if i % 2 == 0 or i % 2 == 2:
messages.append(ciphertext[i])
if i % 2 == 1:
Expand All @@ -58,8 +58,8 @@ def makeroundkey (key1, key2, strings):
## for every even i adds value to
## messages from ciphertexts on pos. i

for i in range (len(messages)):
while len(messages[i])<16:
for i in range(len(messages)):
while len(messages[i]) < 16:
"0" + messages[i]


Expand All @@ -74,20 +74,20 @@ def makeroundkey (key1, key2, strings):
private_key = int(private_key, 16)
#Prepares private key to xor

for w in range (len(messages)):
for w in range(len(messages)):
key = private_key^keys[w]
#Decrypts the key used for particular message

key = hex(key)
key = key.lstrip("0x").rstrip("L")
#Convers keys to hexadecimal value
while len(key)<16:
while len(key) < 16:
key = "0" + key
#Corrects possible length loss

k1 = ""
k2 = ""
for i in range (8):
for i in range(8):
k1 = k1 + key[i]
k2 = k2 + key[i+8]
## Splits the key into 2 smaller keys
Expand Down
64 changes: 33 additions & 31 deletions cryptoim/encryptor_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# encoding: utf-8

"""
Copyright 2013,2014 CryptoIM Development Team
Copyright 2013-2014 CryptoIM Development Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,64 +17,66 @@
limitations under the License.
"""

def Encrypt(plaintext,key):
"""
plaintext = string
key = string (256 bytes)
"""
def Encrypt(plaintext, key):
"""
plaintext = string
key = string (256 bytes)
"""

def KeyExpansion(key):
import hashlib
extendedkey = ''
keyhash = key #Assigns key value to the keyhash, for later use in cycle
keyhash = key # Assigns key value to the keyhash, for later use in cycle
for i in range(32):
keyhash = hashlib.sha224(keyhash.encode('utf-8')).hexdigest()
extendedkey += keyhash
extendedkey = extendedkey[:256]
return extendedkey

def RoundKeySeparator(extendedkey):
"""
Returns list of 16 matrices, these are 128 bit roundkeys used for encryption,
from there 16 matrices will be only 14 used. For opimization purpose was used
index k instead of another cycle.
"""
"""
Returns list of 16 matrices, these are 128 bit roundkeys used for encryption,
from there 16 matrices will be only 14 used. For opimization purpose was used
index k instead of another cycle.
"""
k = 0
roundkeys = []
for k in range(16):
roundkey = [[],[],[],[]] #Matrix (list of lists)
roundkey = [[], [], [], []] # Matrix (list of lists)
for i in range(4):
for j in range(4):
hexadecimal = int(hex(ord(extendedkey[k])),16) #Converts letter to decimal number
roundkey[i].append(hexadecimal)#Appends 4 numbers into each row of matrix
for j in range(4):
# Converts letter to decimal number
hexadecimal = int(hex(ord(extendedkey[k])), 16)
# Appends 4 numbers into each row of matrix
roundkey[i].append(hexadecimal)
k += 1
roundkeys.append(roundkey)
return roundkeys

def SplitMessage(plaintext):
"""
Splits message into 128 bits (16 characters) chunks and each of these
chunks is then transformed into matrix with decimal value. These matrices
are stored into list, creating a list of matrices.
"""
messsage_chunks = []
"""
Splits message into 128 bits (16 characters) chunks and each of these
chunks is then transformed into matrix with decimal value. These matrices
are stored into list, creating a list of matrices.
"""
message_chunks = []
message_chunk = ''
for character in plaintext:
message_chunk += character
if len(message_chunk) == 16: #After 16 characters appends 1 chunk into a list of chunks

# After 16 characters appends 1 chunk into a list of chunks
if len(message_chunk) == 16:
message_chunks.append(message_chunk)
message_chunk = ''
messages = []
for i in range(len(message_chunks)):
matrix = [[],[],[],[]]
matrix = [[], [], [], []]
for j in range(4):
for k in range(4):
number = int(hex(ord(message_chunks[4*i+j])),16) #Cool way to iterate and transform at the same time
# Cool way to iterate and transform at the same time
number = int(hex(ord(message_chunks[4*i+j])), 16)
matrix[j].append(number)
messages.append(matrix)
return messages
"""
TODO: Check if this works as expected
"""




# TODO: Check if this works as expected
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# encoding: utf-8

"""
Copyright 2013,2014 CryptoIM Development Team
Copyright 2013-2014 CryptoIM Development Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tests/TestTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# encoding: utf-8

"""
Copyright 2013,2014 CryptoIM Development Team
Copyright 2013-2014 CryptoIM Development Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tools/pylint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2013,2014 CryptoIM Development Team
# Copyright 2013-2014 CryptoIM Development Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tools/rc_pylint
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ additional-builtins=
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=80
max-line-length=90

# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
Expand Down

0 comments on commit 76e6fa5

Please sign in to comment.