Beispiel #1
0
def indexOfCoincidence(text):
    '''Return the Index of Coincidence for the given text'''
    cypherTxt = utils.stripWhiteSpace(text)
    cypherTxtLength = len(cypherTxt)
    charFreq = characterCounts(cypherTxt)
    sumFreq = sumOfFrequencies(charFreq)
    return calcIoC(sumFreq, cypherTxtLength, charFreq)
Beispiel #2
0
def indexOfCoincidence(text):
    '''Return the Index of Coincidence for the given text'''
    cypherTxt = utils.stripWhiteSpace(text)
    cypherTxtLength = len(cypherTxt)
    charFreq = characterCounts(cypherTxt)
    sumFreq = sumOfFrequencies(charFreq)
    return calcIoC(sumFreq, cypherTxtLength, charFreq)
Beispiel #3
0
 def test_getBestKey(self):
     key1 = vigenere.getBestKey(utils.stripWhiteSpace(cryptoText),
                                'aaaaaaa')
     self.assertEqual(
         key1[0], 'ciphers',
         "Failed to find key.\nExpected: 'ciphers'\nGot: %s Score: %f" %
         key1)
Beispiel #4
0
def init():
    '''Handles command line calls'''
    path = os.getcwd()
    cipherText = utils.openFile(path + '/' + sys.argv[1])
    cipherText = utils.stripWhiteSpace(cipherText)
    key = getKey(cipherText)
    plainText = decryptText(cipherText, key)
    utils.writeFile(path + '/caesar_plain.txt', plainText)
Beispiel #5
0
def init():
    '''Handles command line calls'''
    path = os.getcwd()
    cipherText = utils.openFile(path + '/' + sys.argv[1])
    cipherText = utils.stripWhiteSpace(cipherText)
    key = getKey(cipherText)
    plainText = decryptText(cipherText, key)
    utils.writeFile(path + '/caesar_plain.txt', plainText)
Beispiel #6
0
 def getCurrentParcelInfo(self):
     """Gets data from 'Current Parcel Information' table."""
     'Second Table'
     owner_class_table = self.tables[3]
     owner_values_fields = [
         stripWhiteSpace(x.get_text('', strip=True))
         for x in owner_class_table.findAll('font')
     ]
     owner_dict = dict(zip(*[iter(owner_values_fields)] * 2))
     'Fourth Class'
     property_info_table = self.tables[4]
     property_fields_values = [
         stripWhiteSpace(x.get_text('', strip=True))
         for x in property_info_table.findAll('font')
     ]
     property_class_dict = dict(zip(*[iter(property_fields_values)] * 2))
     ##Merge two dicts
     owner_dict.update(property_class_dict)
     return owner_dict
Beispiel #7
0
def init():
    '''Handles command line calls'''
    path = os.getcwd()
    cypherTxt = utils.openFile(path + '/' + sys.argv[1])
    cypherTxt = utils.stripWhiteSpace(cypherTxt)
    # cypherText = ''.join(reversed(cypherTxt))
    keyLength = ioc.estimateKeyLength(cypherTxt)
    key = findKey(cypherTxt, keyLength)
    print "Final Key: %s of length %d" % (key, keyLength)
    plainText = decryptText(cypherTxt, key)
    utils.writeFile(path + '/vigenere_plain.txt', plainText)
Beispiel #8
0
def init():
    path = os.getcwd()
    text = utils.openFile(path + '/' + sys.argv[1])
    if text is not None:
        text = utils.stripWhiteSpace(text)
        if len(sys.argv) > 2:
            subLength = int(sys.argv[2])
        else:
            subLength = None
        result = getTwinIndex(text, subLength)
        print "Double Count: %s\nText Length: %s\nTwin Index: %s" % (result['dbl'], result['len'], result['ti'])
Beispiel #9
0
 def test_characterCounts(self):
     text = """The opposite wall of this entry was hung all over with a heathenish
      array of monstrous clubs and spears. Some were thickly set with glittering
      teeth resembling ivory saws; others were tufted with knots of human hair;
      and one was sickle-shaped, with a vast handle sweeping round like the segment
      made in the new-mown grass by a long-armed mower. You shuddered as you gazed,
      and wondered what monstrous cannibal and savage could ever have gone a
      death-harvesting with such a hacking, horrifying implement. Mixed with these
      were rusty old whaling lances and harpoons all broken and deformed. Some were
      storied weapons. With this once long lance, now wildly elbowed, fifty years
      ago did Nathan Swain kill fifteen whales between a sunrise and a sunset. And
      that harpoon-so like a corkscrew now-was flung in Javan seas, and run away
      with by a whale, years afterwards slain off the Cape of Blanco. The original
      iron entered nigh the tail, and, like a restless needle sojourning in the
      body of a man, travelled full forty feet, and at last was found imbedded in
      the hump."""
     freq = {
         'e': 103,
         'a': 84,
         'n': 72,
         's': 60,
         't': 58,
         'o': 54,
         'i': 51,
         'r': 47,
         'h': 47,
         'd': 43,
         'l': 43,
         'w': 37,
         'g': 21,
         'u': 21,
         'f': 20,
         'm': 18,
         'y': 17,
         'c': 14,
         'p': 11,
         'b': 11,
         'k': 10,
         'v': 9,
         'j': 2,
         'x': 1,
         'z': 1
     }
     counts = ioc.characterCounts(utils.stripWhiteSpace(text))
     self.assertEqual(
         counts, freq,
         'Mis-counted character frequency.\nExpected:\n%s\nGot:\n%s' %
         (freq, counts))
Beispiel #10
0
    def getHistoricInformation(self):
        """This gets historic information table as array of dictionaries."""
        historic_info_table = self.tables[7]
        historic_fields = [
            x.get_text('', strip=True)
            for x in historic_info_table.findAll("span", class_="datalabel")
        ]
        historic_data = historic_info_table.findAll('tr')[1:]
        historic_info_list = [[
            stripWhiteSpace(p.get_text('', strip=True))
            for p in x.findAll('span')
        ] for x in historic_data]
        if historic_info_list:
            return [dict(zip(historic_fields, x)) for x in historic_info_list]

        return [dict.fromkeys(historic_fields)]
Beispiel #11
0
 def getImprovements(self):
     """Get improvements table as dictionary"""
     improvements_table = self.tables[10]
     improvements_fields = [
         x.get_text('', strip=True)
         for x in improvements_table.findAll("span", class_="datalabel")
     ]
     improvements_data = improvements_table.findAll('tr')[2:]
     improvements_values = [[
         stripWhiteSpace(p.get_text('', strip=True))
         for p in x.findAll('font')
     ] for x in improvements_data]
     if (len(improvements_values) > 0):
         return [
             dict(zip(improvements_fields, x)) for x in improvements_values
         ]
     return [dict.fromkeys(improvements_fields)]
Beispiel #12
0
 def getSalesDisclosure(self):
     """This gets sales disclosure table as array of dictionaries."""
     sales_disclosure_table = self.tables[9]
     sales_disclosure_fields = [
         x.get_text('', strip=True)
         for x in sales_disclosure_table.findAll("span", class_="datalabel")
     ]
     sales_disclosure_data = sales_disclosure_table.findAll('tr')[1:]
     sales_disclosure_info_list = [[
         stripWhiteSpace(p.get_text('', strip=True))
         for p in x.findAll('font')
     ] for x in sales_disclosure_data]
     if sales_disclosure_info_list:
         return [
             dict(zip(sales_disclosure_fields, x))
             for x in sales_disclosure_info_list
         ]
     return [dict.fromkeys(sales_disclosure_fields)]
Beispiel #13
0
 def test_characterCounts(self):
     text = """The opposite wall of this entry was hung all over with a heathenish
      array of monstrous clubs and spears. Some were thickly set with glittering
      teeth resembling ivory saws; others were tufted with knots of human hair;
      and one was sickle-shaped, with a vast handle sweeping round like the segment
      made in the new-mown grass by a long-armed mower. You shuddered as you gazed,
      and wondered what monstrous cannibal and savage could ever have gone a
      death-harvesting with such a hacking, horrifying implement. Mixed with these
      were rusty old whaling lances and harpoons all broken and deformed. Some were
      storied weapons. With this once long lance, now wildly elbowed, fifty years
      ago did Nathan Swain kill fifteen whales between a sunrise and a sunset. And
      that harpoon-so like a corkscrew now-was flung in Javan seas, and run away
      with by a whale, years afterwards slain off the Cape of Blanco. The original
      iron entered nigh the tail, and, like a restless needle sojourning in the
      body of a man, travelled full forty feet, and at last was found imbedded in
      the hump."""
     freq = {'e': 103,
             'a': 84,
             'n': 72,
             's': 60,
             't': 58,
             'o': 54,
             'i': 51,
             'r': 47,
             'h': 47,
             'd': 43,
             'l': 43,
             'w': 37,
             'g': 21,
             'u': 21,
             'f': 20,
             'm': 18,
             'y': 17,
             'c': 14,
             'p': 11,
             'b': 11,
             'k': 10,
             'v': 9,
             'j': 2,
             'x': 1,
             'z': 1}
     counts = ioc.characterCounts(utils.stripWhiteSpace(text))
     self.assertEqual(counts, freq, 'Mis-counted character frequency.\nExpected:\n%s\nGot:\n%s' % (freq, counts))
Beispiel #14
0
 def test_getBestKey(self):
     key1 = vigenere.getBestKey(utils.stripWhiteSpace(cryptoText), 'aaaaaaa')
     self.assertEqual(key1[0], 'ciphers', "Failed to find key.\nExpected: 'ciphers'\nGot: %s Score: %f" % key1)
Beispiel #15
0
 def Key(self):
     global cryptoText
     parent = 'BBBBAAA'
     index = 4
     text = utils.stripWhiteSpace(cryptoText)
     bestKey = vigenere.testKey(parent, index, text)
Beispiel #16
0
 def Key(self):
     global cryptoText
     parent = 'BBBBAAA'
     index = 4
     text = utils.stripWhiteSpace(cryptoText)
     bestKey = vigenere.testKey(parent, index, text)