1. meisterluk
  2. cryptotools

Commits

meisterluk  committed 00a9ecd

Source code beautification.

  • Participants
  • Parent commits 6a2ef2f
  • Branches default

Comments (0)

Files changed (25)

File __init__.py

View file
 DIR_LFREQ = 'data/letter_frequency'
 
 def get_content(filename):
-    fp = open(filename)
-    content = fp.read()
-    fp.close()
+    """Return the content of a text file as a string"""
+    with open(filename) as fp:
+        content = fp.read()
     return content
 
 if __name__ == '__main__':

File adfgvx.py

View file
 import errors
 
 class ADFGVX(object):
-    ''' 
+    '''
     ADFGVX-Encryption
     ~~~~~~~~~~~~~~~~~
 
     '''
 
     def __init__(self, encrypt=None, key=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.encrypt = encrypt
         self.key = key
         self.text = text
         self.charset[1] = map(chr, range(65, 91))
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')
             valid = ('e', 'y', 't', '1', 1, '')
             print
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.text = 'foobarprogrammer'
         self.key = ('codierungabfhjkklmpqstvwxyz9876543210', 'foobarer')
 
     def valid_key1(self, key, correct=False):
-        ''' Checks the validity of the key and repairs it (if specified) '''
+        '''Checks the validity of the key and repairs it (if specified) '''
         valid = self.charset[0]
         checkdict = dict(zip(valid, (False,) * len(valid)))
         if len(key) != len(valid):
             return key
 
     def valid_key2(self, key, text, correct=False):
-        ''' Checks the validity of the second key and repairs it \
+        '''Checks the validity of the second key and repairs it \
                 (if specified) '''
         valid = self.charset[1]
         checkdict = dict(zip(valid, (False,) * len(valid)))
             return key
 
     def valid_code(self, code):
-        ''' Check validity of code '''
+        '''Check validity of code'''
         valid = 'ADFGVX'
         if len(code) % 2 == 1:
             return False
         return True
 
     def valid_text(self, text):
-        ''' Check validity of text '''
+        '''Check validity of text'''
         limit = 100
         if len(text) < 6 or len(text) >= limit:
             return False
         return True
 
     def euklid(self, a, b):
-        ''' Calculates the biggest factor between two numbers '''
+        '''Calculates the biggest factor between two numbers'''
         while b != 0:
             a, b = b, a % b
         return a
 
     def sieve_of_eratosthenes(self, maximum):
-        ''' Implementation of Eratosthenes' Sieve '''
+        '''Implementation of Eratosthenes' Sieve'''
         primes = [False, False] + [True] * (maximum - 2)
         result = 0
         next = 2
         return primes
 
     def decode(self):
-        ''' ADFGVX-Decryption '''
+        '''ADFGVX-Decryption'''
         # damn it... this was so much work
         if None in (self.encrypt, self.key, self.text):
             raise errors.ConfigurationError(1)
         return text
 
     def encode(self):
-        ''' ADFGVX-Encryption '''
+        '''ADFGVX-Encryption'''
         if None in (self.encrypt, self.key, self.text):
             raise errors.ConfigurationError(1)
         code = 'ADFGVX'
         return encoded
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run De/En-cryption-function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else:

File caesar.py

View file
     '''
 
     def __init__(self, encrypt=None, key=None, charset=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.encrypt = encrypt
         self.key = key
         self.charset = charset
         self.text = text
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')
             valid = ('e', 'y', 't', '1', 1, '')
         self.key = self.key % len(self.charset)
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = 3
         self.charset = map(chr, range(65, 91) + range(97, 123))
         self.text = 'Foobar'
 
     def decode(self, quiet=False):
-        ''' Caesar-Decryption '''
+        '''Caesar-Decryption'''
         if None in (self.key, self.charset, self.text):
             raise errors.ConfigurationError
         output = ''
         return output
 
     def encode(self):
-        ''' Caesar-Encryption '''
+        '''Caesar-Encryption'''
         if None in (self.encrypt, self.key, self.charset, self.text):
             raise errors.ConfigurationError(1)
         output = ''
         return output
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run De/En-cryption-function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else:

File calc_120.py

View file
 import euklid
 
 def run():
-        num = 143
-        teiler = 0
+    num = 143
+    teiler = 0
 
-        for x in xrange(num):
-            if euklid.euclidean(x, num) == 1:
-                teiler += 1
+    for x in xrange(num):
+        if euklid.euclidean(x, num) == 1:
+            teiler += 1
 
-        e = 157
-        d = 1
+    e = 157
+    d = 1
 
-        while (e * d) % teiler != 1:
-            d += 1
+    while (e * d) % teiler != 1:
+        d += 1
 
-        return d
+    return d
 
 if __name__ == '__main__':
     print run()

File calc_endless_primes.py

View file
 #!/usr/bin/env python
 
-primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)
+primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
 
 def product(factors):
     product = 1

File calc_even_numbers.py

View file
                 output += "%d * %d is even\n" % (i, j)
 
     if even:
-        output += "\nWhen you multiplicate two even numbers " + \
+        output += "\nIf you multiplicate two even numbers " + \
                 "(here: smaller than 1000), you get an even number\n"
     else:
         output += "\nMath error.\n"

File calc_hvaduhlqpdo.py

View file
 from utils import prefix
 
 def run():
-    print 'I will only calculate with all lowercase characters'
+    print 'I will calculate with lowercase characters only'
     print 'press <enter> to insert "Hv adu hlqpdo"'
     code = raw_input('Which text shall I decode? ')
     if code == '':

File coincidence_index.py

View file
 content = get_content(filename)
 
 def get_values(text):
-    ''' Get percentages of files (specific structure) '''
+    '''Get percentages of files (specific structure)'''
     values = []
     for line in text.split("\n"):
         if line != '':

File dez_bin.py

View file
     Copyright: GPL
 '''
 
-def dez_bin(arg):
-    ''' Convert decimal numbers to binary numbers '''
+def dec_bin(arg):
+    '''Convert decimal numbers to binary numbers'''
     arg = int(arg)
     base = 2
     bin = ''
     return bin[::-1]
 
 def bin_dec(arg):
-    ''' Convert binary numbers to decimal numbers '''
+    '''Convert binary numbers to decimal numbers'''
     dec = 0
     exponent = 0
     for bin in list(arg).__reversed__():
     return dec
 
 bin_dez = bin_dec
+dez_bin = dec_bin
+
 
 if __name__ == '__main__':
-    print '20 is binary', dez_bin(20)
-    print '10100 is decimal', bin_dec('10100')

File errors.py

View file
 #!/usr/bin/env python
 
 class ConfigurationError(Exception):
+    """Custom Exception: ConfigurationError"""
+
     def __init__(self, value=None):
         self.value = value
+
     def code(self, c):
         if c == 0:
             return 'Unknown error.'
         elif c == 1:
             return "You did not set the configuration parameters.\n " \
                     + 'You might want to use default()'
+
     def __str__(self):
         return self.code(self.value)
 
+
 if __name__ == '__main__':
     cg = ConfigurationError()
     print cg.code(1)

File homophone_row.py

View file
 
     def __init__(self, encrypt=None, key=None, charset=None, \
             text=None, sep=None):
-        ''' Set default values '''
+        '''Set default values'''
         self.encrypt = encrypt
         self.key = key
         self.charset = charset
         self.separator = sep
 
     def list2dict(self, liste):
-        ''' Create a dictionary based on a list (set keys with numbers) '''
+        '''Create a dictionary based on a list (set keys with numbers) '''
         dicti = { }
         for (key, item) in enumerate(liste):
             dicti[key] = item
         return dicti
 
     def import_key(self, string, other_sep=None):
-        ''' Import a key for en/decryption '''
+        '''Import a key for en/decryption'''
         dicti = {}
         if other_sep is None:
             sep = self.separator
         return dicti
 
     def export_key(self, other_sep=None):
-        ''' Export key of en/decryption '''
+        '''Export key of en/decryption'''
         if other_sep is None:
             sep = other_sep
         else:
         return key
 
     def generate_key(self, text=None):
-        ''' This will generate an appropiate key to the text '''
+        '''This will generate an appropiate key to the text'''
         if text == None:
             text = self.text
         else:
         return key
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')
             valid = ('e', 'y', 't', '1', 1, '')
             self.text = text
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = self.list2dict(map(chr, range(65, 91) + range(97, 123)))
         self.text = 'Foobar'
         self.separator = (':', ',', ',')
 
     def decode(self):
-        ''' Homophone-row-Decryption '''
+        '''Homophone-row-Decryption'''
         if None in (self.key, self.text, self.separator):
             raise errors.ConfigurationError(1)
         output = ''
         return output
 
     def encode(self):
-        ''' Caesar-Encryption '''
+        '''Caesar-Encryption'''
         if self.key == '' or self.key == None:
             print 'I did not find any valid key. I generated one'
             self.key = self.generate_key()
         return output.strip(self.separator[2])
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run De/En-cryption-function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else:

File interface.py

View file
             if selection.has_key(item):
                 print ' (' + item + ')', selection[item][0]
         print
-        select = raw_input('Which option would you like to start? ')
+        try:
+            select = raw_input('Which option would you like to run? ')
+        except (EOFError, KeyboardInterrupt):
+            select = 'q'
+
         if select == 'q':
             exit = True
         elif selection.has_key(select):

File md5_brute_force.py

View file
 import time
 
 def next_letter(letter):
-    ''' Returns next character; character list is not endless ([9]+1 = False) '''
+    '''Returns next character; character list is not endless ([9]+1 = False)'''
     charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
     #if letter == charset[len(charset)-1]:
     #    return False
     #    return a
 
 def next_word(length, current=False):
-    ''' Returns next word in alphabetical order '''
+    '''Returns next word in alphabetical order'''
     if current:
         current = list(current[0:length])
         working_pos = len(current) - 1

File morse.py

View file
     for more details.
 
     see <http://gnu.org/license/> 
-'''
+    '''
 
     def __init__(self, encrypt=None, sep=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.encrypt = encrypt
         self.separator = sep
         self.text = text
 
     @staticmethod
     def split_by(text, split, maxsplit=None):
-        ''' Will split a text by using a list of chars
+        '''Will split a text by using a list of chars
         eg. 
             split_by('foo bar', (' ',)) == ('foo', 'bar')
             split_by('foo bar', (' ', 'a')) == ('foo', 'b', 'r')
         return result
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')
             valid = ('e', 'y', 't', '1', 1, '')
             self.text = text
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.separator = ("\n", "\t", ' ')
         self.text = 'Foobar'
 
     def decode(self):
-        ''' Morse-Decryption '''
+        '''Morse-Decryption'''
         if None in (self.separator, self.text):
             raise errors.ConfigurationError(1)
         output = ''
         return output
 
     def encode(self):
-        ''' Morse-Encryption '''
+        '''Morse-Encryption'''
         if None in (self.separator, self.text):
             raise errors.ConfigurationError(1)
         output = ''
         return output
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run De/En-cryption-function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else:

File register.py

View file
 #!/usr/bin/env python
 
-''' General information: 
+'''General information: 
 Never use this for cryptographic proposes
 
 use os.random
 aka /dev/random 
-instead '''
+instead'''
 
 import time
 import math
 # TODO: it would be beautiful to work with threads
 
 class ShiftRegister(object):
+    """Implementation of a simple shift register"""
+
     def __init__(self, config, init=None, problem=True):
         self.length = len(config)
         self.prob = problem
         else:
             self.config = config
             self.pos = init
+
     def __len__(self):
         return self.length
+
     def __getitem__(self, item):
         return self.pos[item]
+
     def __setitem__(self, identity, value):
         self.pos[identity] = value
+
     def set(self, items):
         self.pos = items
+
     def get(self):
         return self.pos
+
     def random(self):
         register = []
         for i in xrange(self.length):
             else:
                 register.append(0)
         return register
+
     def is_valid_register(self, reg):
         if len(reg) != self.length:
             return False
             if not self.only_binary(i):
                 return False
         return True
+
     def only_binary(self, value):
         try:
             value = int(value)
             return True
         else:
             return False
+
     def reversed_iteration(self, x):
         i = len(x)
         while i > 0:
             i -= 1
             yield x[i]
+
     def problem(self):
         if tuple(self.pos) == (0,) * self.length:
             return True
         else:
             return False
+
     def next(self):
         # self.pos, self.config, self.length are set
         # (a xor b) is ((a+b) % 2)
 
 
 class Random(object):
-    ''' This stupid class tries to be a clone of the random module,
-    but works with ShiftRegister() '''
+    '''This stupid class tries to be a clone of the random module,
+    but works with ShiftRegister()
+    '''
+
     def __init__(self):
-        ''' Initializing.
+        '''Initializing.
         
         self.sr - contains an instance of ShiftRegister()
         self.items - contains the items for the ShiftRegister module
         return int(milli[-9:1:-1]) * 10**(-5) # reversed and cut
 
     def randomize(self):
-        ''' self.sr.next()s self.sr.pos' items random times '''
+        '''self.sr.next()s self.sr.pos' items random times'''
         ## epic fail
         #a = time.time()
         #time.sleep(0.0123)
 
     # this is simply a fail in concept. it has the same aim like sr.next()
     #def shuffle(self):
-        #''' This simply shuffles the 4 items of self.init
+        #'''This simply shuffles the 4 items of self.init
         
         #0, 2 = 2, 0
         #1 = 1 & 0
         #self.item[3] = self.item[2] | self.item[0]
 
     def gen_dict(self):
-        ''' Generates a dict with strings of all possibilities 
+        '''Generates a dict with strings of all possibilities 
         
-        only for test methods '''
+        only for test methods'''
         return {'[0, 0, 0, 0]' : 0, '[1, 0, 0, 0]' : 0, '[0, 1, 0, 0]' : 0,
                 '[0, 0, 1, 0]' : 0, '[0, 0, 0, 1]' : 0, '[1, 1, 0, 0]' : 0,
                 '[0, 1, 1, 0]' : 0, '[0, 0, 1, 1]' : 0, '[1, 0, 1, 0]' : 0,
                 '[1, 1, 1, 1]' : 0}
 
     def test_sr(self):
-        ''' This function tests the functionality of randomize '''
+        '''This function tests the functionality of randomize'''
         # about 87 sec with 1.1 GHz
         testdict = self.gen_dict()
         for i in xrange(1000):
         pprint.pprint(testdict)
 
     def test_random(self):
-        ''' This function tests the random module '''
+        '''This function tests the random module'''
         # about 0.04601 sec with 1.1 GHz
         testdict = self.gen_dict()
         for i in xrange(1000):
         return value
 
     def select(self, code, values):
-        ''' Selects a value based on a code
+        '''Selects a value based on a code
         This is a recursive algorithm
         
         [0,1,0] and [3,4,5] returns 4
         [1,0,1] and [3,4,5] returns 3 
-        [0,0,0] and [3,4,5] returns 5 '''
+        [0,0,0] and [3,4,5] returns 5
+        '''
         # stupid
         selection = []
         for key, item in enumerate(values):
             return selection[0]
 
     def choice(self, values):
-        ''' Selects an item out of items
+        '''Selects an item out of items
 
         It generates a randomized key with ShiftRegister 
         (keylength has to be adapted) and selects one 

File rot18.py

View file
     '''
 
     def __init__(self, encrypt=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.encrypt = encrypt
         self.key = 18
         self.charset = string.ascii_uppercase + string.digits
         self.text = text
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = 18
         self.charset = string.ascii_uppercase + string.digits

File rot47.py

View file
     '''
 
     def __init__(self, encrypt=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.encrypt = encrypt
         self.key = 47
         self.charset = map(chr, range(33, 127))
         self.text = text
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = 47
         self.charset = map(chr, range(33, 127))

File rot5.py

View file
     '''
 
     def __init__(self, encrypt=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         charset = string.digits
         self.encrypt = encrypt
         self.key = 5
         self.text = text
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = 5
         self.charset = string.digits

File rsa.py

View file
     '''
 
     def __init__(self, encrypt=None, key=None, sep=',', text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.encrypt = encrypt
         self.key = key
         self.charset = (33, 127)
         self.sep = sep
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         valid = ('e', 'k', 'y', 't', '1', 1, '')
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')

File skytala.py

View file
 
 
     def __init__(self, encrypt=None, skytale=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.skytale = skytale
         self.text = text
         self.encrypt = encrypt
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')
             valid = ('e', 'y', 't', '1', 1, '')
             self.text = raw_input('Which text shall I use? ')
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.skytale = 6
         self.text = 'Foobar'
 
     def decode(self):
-        ''' This will simulate an old skytala-decryption of sparta '''
+        '''This will simulate an old skytala-decryption of sparta'''
         if None in (self.skytale, self.text):
             raise errors.ConfigurationError(1)
         skytale, text = self.skytale, self.text
         return output
 
     def encode(self):
-        ''' This will simulate an old skytala-encryption of sparta '''
+        '''This will simulate an old skytala-encryption of sparta'''
         if None in (self.skytale, self.text):
             raise errors.ConfigurationError(1)
         output = ''
         return output
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run De/En-cryption-function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else:

File square_and_multiply.py

View file
 #!/usr/bin/env python
 # rsa-tools 1.2 status OK
 
-import dez_bin
+import utils
 
 def square(base, c):
     times = 0
     return a
 
 def square_and_multiply(a, c, m):
-    b = dez_bin.dez_bin(c)
+    b = utils.dez_bin(c)
 
     res = 1
     times = 0
 
     print 'a is', a
     print 'c is', c
-    print 'b is the binary value of c (%s)' % dez_bin.dez_bin(c)
+    print 'b is the binary value of c (%s)' % utils.dez_bin(c)
     print 'm is', m
     print '... and ...'
     print '(a**c mod m) is (%d)' % square_and_multiply(a, c, m)

File transposition.py

View file
 import errors
 
 class Transposition(object):
-    ''' 
+    '''
     Transposition-Encryption
     ~~~~~~~~~~~~~~~~~~~~~~~~
 
     '''
 
     def __init__(self, encrypt=None, key=None, text=None):
-        ''' Initialize; write values into object namespace '''
+        '''Initialize; write values into object namespace'''
         self.encrypt = encrypt
         self.key = key
         self.text = text
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')
             valid = ('e', 'y', 't', '1', 1, '')
             self.text = raw_input('Give me the text: ')
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = 5
         self.text = 'Foobar'
 
     def encode(self):
-        ''' Transposition Encryption '''
+        '''Transposition Encryption'''
         if None in (self.encrypt, self.key, self.text):
             raise errors.ConfigurationError(1)
         output = ''
         return output
 
     def decode(self):
-        ''' Transposition Decryption '''
+        '''Transposition Decryption'''
         if None in (self.encrypt, self.key, self.text):
             raise errors.ConfigurationError(1)
         tmp = len(self.text) / self.key
         return self.encode()
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run De/En-cryption-function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else:

File utils.py

View file
     return d
 
 def dez_bin(arg):
-    ''' Convert decimal numbers to binary numbers '''
+    '''Convert decimal numbers to binary numbers'''
     arg = int(arg)
     base = 2
     bin = ''

File vigenere.py

View file
     see <http://gnu.org/license/> 
     '''
     def __init__(self, encrypt=None, key=None, charset=None, text=None):
-        ''' Set default values '''
+        '''Set default values'''
         self.encrypt = encrypt
         self.key = key
         self.charset = charset
         self.text = text
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         if self.encrypt == None:
             encrypt = raw_input('Shall I (e)ncode or (d)ecode? ')
             valid = ('e', 'y', 't', '1', 1, '')
             self.text = text
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = 'Foobar'
         self.charset = map(chr, range(65, 91) + range(97, 123))
         self.text = 'Foobar'
 
     def stretch_key(self):
-        ''' Stretchs the key to the size of self.text \
-        (as required for en/decryption) '''
+        '''Stretches the key to the size of self.text \
+        (as required for en/decryption)'''
         if None in (self.key, self.text):
             print 'Non-critical error:', \
                 'Cannot stretch_key() before text and key are set'
         self.key += self.key[0:(len(self.text)-len(self.key))]
 
     def tabula_recta(self, charset=None):
-        ''' Will display the tabula recta '''
+        '''Will display the tabula recta'''
         if (not isinstance(charset, list)) or (not isinstance(charset, tuple)):
             charset = self.charset
         if charset == None:
         return output
 
     def decode(self):
-        ''' Vigenere-Decryption '''
+        '''Vigenere-Decryption'''
         if None in (self.key, self.charset, self.text):
             raise errors.ConfigurationError(1)
         # prefer to make it double than never
         return output
 
     def encode(self):
-        ''' Vigenere-Encryption '''
+        '''Vigenere-Encryption'''
         if None in (self.encrypt, self.key, self.charset, self.text):
             raise errors.ConfigurationError(1)
         # prefer to make it double than never
         return output
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run de/encryption function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else:

File xor.py

View file
     see <http://gnu.org/license/> 
     '''
     def __init__(self, encrypt=None, key=None, text=None):
-        ''' Set default values '''
+        '''Set default values'''
         self.encrypt = encrypt
         self.key = key
         self.text = text
 
     def request(self):
-        ''' Request values for encryption parameters '''
+        '''Request values for encryption parameters'''
         # XOR encode and decode are the same
         self.encrypt = True
         if self.key == None:
             self.key = '2'
             while False in [False for x in self.key if x not in ('0', '1')]:
-                self.key = raw_input('Which key shall I use (str, {0,1})? ')
+                self.key = raw_input('Which key shall I use (str, {0,1})?  ')
         if self.text == None:
             self.text = raw_input('Which text shall I use (str, {0,1})? ')
             if len(self.text) != len(self.key):
                 self.stretch_key()
 
     def default(self):
-        ''' Set parameters to default values '''
+        '''Set parameters to default values'''
         self.encrypt = True
         self.key = '1010'
         self.text = '1100'
 
     def stretch_key(self):
-        ''' Stretchs the key to the size of self.text \
-        (as required for en/decryption) '''
+        '''Stretches the key to the size of self.text \
+        (as required for en/decryption)'''
         if None in (self.text, self.key) or '' in (self.text, self.key):
             raise errors.ConfigurationError(1)
         if len(self.text) == len(self.key):
                 counter += 1
 
     def decode(self):
-        ''' XOR-Decryption
+        '''XOR-Decryption
         
-        As you know, this is the same like encode '''
+        As you know, this is the same like encode
+        '''
         return self.encode()
 
     def encode(self):
-        ''' XOR-Encryption 
+        '''XOR-Encryption 
        
         just to sum it up... bitwise operations:
           0|1 OR  (0111)
         return result
 
     def run(self):
-        ''' Will run De/En-cryption-function as defined in self.encrypt '''
+        '''Will run De/En-cryption-function as defined in self.encrypt'''
         if self.encrypt:
             return self.encode()
         else: