Exemplo n.º 1
0
    def calc_hash(self):  #更新整棵树的hash值
        self.node = []
        self.cstr = []
        tmp2 = []
        cnt = len(self.data)
        n = len(self.data)

        for i in range(n):
            tmp = str(self.data[i].h) + str(self.data[i].r) + zsign.to_str(
                self.data[i])
            if self.data[i].sigma != None and not (zsign.verify(
                    tmp, self.data[i].sigma, self.data[i].pk)):
                print('MSIG!')
                pass

            if self.data[i].sigma == None:
                tmp2.append('0' * 200)
                self.cstr.append('')
            elif chrs.HashCheck_CHRS(self.data[i].mpk, self.data[i].spk,
                                     self.data[i].h, self.data[i].r,
                                     self.data[i].arbitrary):
                tmp2.append(hex(self.data[i].h)[2::])
                self.cstr.append(self.data[i].r)
            else:
                print(zsign.to_str(self.data[i]))
                print('MCHRS!')

            standard_part = zsign.to_str(
                self.data[i],
                ['h', 'r', 'sigma', 'spk', 'pk', 'mpk', 'arbitrary'])
            if self.data[i].sigma != None:
                ht, rt = Hash.Hash(RSA.importKey(self.data[i].pk),
                                   standard_part)
                ht = hex(ht)[2::]
                rt = hex(rt)
            else:
                ht = '0' * 200
                rt = ''
            tmp2.append(ht)
            self.cstr.append(rt)

        cnt = 2 * n
        self.node.append(tmp2)
        #print(len(tmp2),cnt)
        #print(len(self.data))

        while cnt > 1:  #其余层
            tmp = []
            for i in range(0, cnt, 2):
                tmp1 = self.node[-1][i]
                if i + 1 < len(self.node[-1]):
                    tmp2 = self.node[-1][i + 1]
                else:
                    tmp2 = ''
                tmp.append(zsign.sha256(tmp1 + tmp2))
            cnt = cnt // 2
            self.node.append(tmp)
        return self.node[-1][0]  #返回树根hash值
Exemplo n.º 2
0
    def __getitem__(self, key):
        if type(key) is not str:
            raise TypeError

        with open(self._index_path, mode="rb") as self._index:
            # read header
            self.word_len = struct.unpack("I", self._index.read(4))[0]
            self.format_string = str(self.word_len) + "sII"
            self.chunk_size = struct.calcsize(self.format_string)
            self._index

            # Get word list boundaries
            low, high = Hash.Hash("hash.dat")[key]
            # Get the offset and length of the index list
            offset, length = self.binary_search(key, low, high)

        with open(self._link_path, mode="rb") as f:
            return Links.Links(f).get(offset, length)
Exemplo n.º 3
0
    def build(self, korpus):
        # Reading all words from our korpus
        words, word_len = self.parse_korpus(korpus)
        print("Läst alla ord..")

        self.word_len = word_len

        # Build the word Links index file
        links_words = []
        with open(self._link_path, mode="wb") as f:
            self._links = Links.Links(f)
            links_words = self._links.build(
                words)  # from Links: (word, offset, size)

        # Build the main Index file
        word_indices = self.write(self._index_path, links_words, self.word_len)

        # Build the Hash index file
        self._hash = Hash.Hash("hash.dat", word_indices)
Exemplo n.º 4
0
    # Take in from command line arguments
    else:
        input = sys.argv[1] # sys.argv[0] is this file's name (Driver.py)
    
    # Does this input exists and is input a file (not a directory).
    if os.path.exists(input) or os.path.isfile(input):
        file = open(input, 'r') # open file for reading
        parser = Parser.Parser(file) # construct new parser object.
        (count, color, steps, board) = parser.parse() # Parse the file.
        file.close()


        if count == "1":
            print MoveGenerator.MoveGenerator.randSetup(color)
        else:           
            hash = Hash.Hash()  # Construct a new hash
            hash.calculateHashkey(board)  # Calculate the hash key for this given board.

	    nega = Negascout.Negascout(board, color)
	    unfilteredAnswer = nega.negascout(3,(-999999,"",board,hash.get_hashkey()), (999999,"",board,hash.get_hashkey()), board, color, steps, count, hash)
	    unfilteredMoves = unfilteredAnswer[1].split('|')
	    filteredAnswer = (unfilteredAnswer[0], unfilteredMoves[1])
            print unfilteredMoves[1].strip()
	    Common.displayBoard(unfilteredAnswer[2])
        
     
     
    else:
        print "File not found"
        
        
Exemplo n.º 5
0
# Run this file first
# Program to initialise the save file.

from Vehicle import *
from Person import *
from Hash import *
from Menu import *
from os import system, name
import pickle

if __name__ == "__main__":
    with open('hashowner.txt', 'wb') as output:
        hashO = Hash(30)
        pickle.dump(hashO, output, pickle.HIGHEST_PROTOCOL)
    with open('hashregvehicle.txt', 'wb') as output:
        hashRV = Hash(30)
        pickle.dump(hashRV, output, pickle.HIGHEST_PROTOCOL)
Exemplo n.º 6
0
import Hash

tabla = Hash.Hash(9)

tabla.insertar(5,10)
tabla.insertar(28,20)
tabla.insertar(19,30)
tabla.insertar(15,30)
tabla.insertar(20,40)
tabla.insertar(33,4)
tabla.insertar(12,5)
tabla.insertar(17,6)
tabla.insertar(10,7)
print(tabla.tabla)