Exemplo n.º 1
0
 def gen_next_block(self, public_key, transactions):
     prev_block = self.chain[-1]
     index = prev_block.index + 1
     timestamp = datetime.datetime.now()
     data = transactions
     hashed_block = prev_block.gen_hashed_block()
     self.chain.append(
         Block(index, timestamp, data, hashed_block, public_key))
Exemplo n.º 2
0
    def __init__(self, name: str, body_of_acl: str, parent: object = None):
        self.name = name
        self.parent = parent
        self.interfaces = set()
        self.ip_interfaces = set()
        self.calculated_networks = set()
        self.calculated_statics = set()
        if CONFIG_CLASS and isinstance(self.parent, config_class.Cisco_Config):
            self.interfaces = set(self.parent._find_ace_interfaces(self.name))
            for intface in self.interfaces:
                self.ip_interfaces.update(self.parent._get_subnets(intface))
            if self.interfaces and self.ip_interfaces:
                for address in self.ip_interfaces:
                    self.calculated_networks.add(
                        self._calculate_address(address))
                for address in self.ip_interfaces:
                    static_route = self._calculated_statics(address)
                    if static_route:
                        self.calculated_statics.add(static_route)

        self.blocks = []
        raw_blocks = self._break_into_blocks(body_of_acl)
        for block in raw_blocks:
            self.blocks.append(Block(block, parent=self))
import pygame
from pygame import *
import block_class
from block_class import Block
from GraphicsUtil import toplength, topwidth

blockWidth = 25
x = 0
y = 0

squiggleSurface2 = pygame.Surface((75,50))
squiggleSurface2.set_colorkey((0,0,0))


B1 = Block(blockWidth,blockWidth, (0,255,255), x, y)

B1.groupDrawSquiggleBlock2(squiggleSurface2)


class squiggleBlock2:
    def __init__(self):
        self.color = 6
        self.surface = squiggleSurface2
        self.rotate = 0      
    
    def points(self):   
        if self.rotate%2==0:
            return [(0,0), (1,0), (1,1), (2,1)]
        if self.rotate%2==1:
            return [(1,0), (0,1), (1,1), (0,2)]
import pygame
from pygame import *
import block_class
from block_class import Block
from GraphicsUtil import toplength, topwidth

blockWidth = 25
lineXpos = 0
lineYpos = 0

BLUE = (0,0,255)

lineSurface = Surface((25,100))
lineSurface.set_colorkey((0,0,0))

B1 = Block(blockWidth,blockWidth, BLUE, lineXpos, lineYpos)

B1.groupDrawLineBlock(lineSurface)


class lineBlock:
    def __init__(self):
        self.color = 2
        self.surface = lineSurface
        self.rotate = 0

    def points(self):
        if self.rotate%2==0:
            return [(0,0), (0,1), (0,2), (0,3)]
        if self.rotate%2==1:
            return [(0,0), (1,0), (2,0), (3,0)]
import pygame
from pygame import *
import block_class
from block_class import Block
from GraphicsUtil import toplength, topwidth

blockWidth = 25
x = 0
y = 0

squiggleSurface = pygame.Surface((75,50))
squiggleSurface.set_colorkey((0,0,0))


B1 = Block(blockWidth,blockWidth, (0,255,255), x, y)

B1.groupDrawSquiggleBlock(squiggleSurface)


class squiggleBlock:
    def __init__(self):
        self.color = 5
        self.surface = squiggleSurface
        self.rotate = 0
        
    def points(self):
        if self.rotate%2==0:
            return [(0,1), (1,0), (2,0), (1,1)]
        if self.rotate%2==1:
            return [(0,0), (0,1), (1,1), (1,2)]
       
from pygame import *
import block_class
from block_class import Block
from GraphicsUtil import toplength, topwidth
import GraphicsUtil as Graph

blockWidth = 25
x = 0
y = 0
YELLOW = (255, 255, 0)


lSurface = pygame.Surface((75,50))
lSurface.set_colorkey((0,0,0))

B1 = Block(blockWidth,blockWidth, YELLOW, x, y)
B1.groupDrawlBlock(lSurface)

class lBlock:
    def __init__(self):
        self.color = 3
        self.surface = lSurface
        self.rotate = 0
    
    def points(self):
        if self.rotate%4==0:
            return [(0,0), (1,0), (2,0), (0,1)]
        if self.rotate%4==3:
            return [(0,0), (0,1), (0,2), (1,2)]
        if self.rotate%4==2:
            return [(0,1), (1,1), (2,1), (2,0)]
Exemplo n.º 7
0
def gen_genesis_block():
    transaction = [{"Serial": "Genesis", "PubKey": "Placeholder"}]
    return Block(0, datetime.datetime.now(), transaction, "0", "0")
def draw(screen):
    #print(score)
    global currentblock, y, x, state, me
    if state == gameState: 
        # # setup a different background, 
        # if Graph.TGrid[y][x] != 0:
        #     y = 0
        #     x = 4
        #     currentblock = randomeBlock()
        screen.fill(Graph.BLACK)
        screen.blit(Graph.grid, (0, 0))
        

        def drawTetramino(x , y, block):
            pts = block.points()
            for p in pts:
                px, py = x+p[0], y+p[1]
                screen.blit(block.surface, (px*25+Graph.toplength, py*25+Graph.topwidth))
        
        drawTetramino(x, y, currentblock)

        for i in range (len(Graph.TGrid)):
            for j in range (len(Graph.TGrid[i])):
                loc = Graph.TGrid [i][j]
                if loc != 0:
                    if loc == 1:
                        b = Block(25,25, (255,0,0), j, i)
                        b.indBlock(screen,block_class.yellowBlock)
                    elif loc == 2:
                        b = Block(25,25, (255,0,0), j, i)
                        b.indBlock(screen,block_class.tealBlock)
                    elif loc == 3:
                        b = Block(25,25, (255,0,0), j, i)
                        b.indBlock(screen,block_class.redBlock)
                    elif loc == 4:
                        b = Block(25,25, (255,0,0), j, i)
                        b.indBlock(screen,block_class.greenBlock)
                    elif loc == 5:
                        b = Block(25,25, (255,0,0), j, i)
                        b.indBlock(screen,block_class.blueBlock)
                    elif loc == 6:
                        b = Block(25,25, (255,0,0), j, i)
                        b.indBlock(screen,block_class.orangeBlock)
                    elif loc == 7:
                        b = Block(25,25, (255,0,0), j, i)
                        b.indBlock(screen,block_class.purpleBlock)



        # Clear a row and score when complete
        bonus = -50
        for i in Graph.TGrid:
            global score, tick, permtick, level
            if 0 not in i:
                Graph.TGrid.remove(i)
                Graph.TGrid.insert(0,[0,0,0,0,0,0,0,0,0,0])
                score += 100
                level += 100
                bonus += 50
                if level >= 500:
                    level -= 500
                    permtick += 8
                    tick += 8
                
        if bonus >= 0:
            score += bonus
            level += bonus
            # return score
        text = font.render(str(score),1,(255,255,255))
   
        #Draws Boxes On The Side
        screen.blit(Graph.scoreSurface, (325, 400))
        
        screen.blit(Graph.scoreWordSurface, (325, 330))
        
        screen.blit(text, (335,415))

        screen.blit(Graph.nextSurface, (325, 50))

        screen.blit(Graph.nextShowSurface, (325, 115))

        drawTetramino(14.5, 6, nextBlock)
        
        screen.blit(Graph.gridGraphicSurface, (0, 0))  
        

        #Draws Box Behind Grid
        #screen.blit(Graph.gridGraphicSurface, (18, 5))  
    
    elif state == endGameState:
        

        # pygame.mixer.music.stop()

    
        
       # print ('endgame called')
        pygame.display.flip()

        endScoreSurface = pygame.Surface((200, 50))
        endScoreImage = pygame.image.load("ScoreBox.png")
        endScoreImage = pygame.transform.scale(endScoreImage, (200, 50))
        endScoreSurface.blit(endScoreImage, (0, 0))
        
        

        screen.fill(Graph.BLACK)
        text = font.render('Score: ' + str(score),1,(255,255,255))
        text2 = font.render('press M to return to menu',1,(255,255,255))
        screen.blit(endScoreSurface, (185,235))
        screen.blit(text, (205,250))
        screen.blit(text2, (130,450))
        


    elif state == menuState:       
        resetGame()
        pygame.display.flip()
        

       # print ('menu state called')
        screen.fill(Graph.BLACK)
        screen.blit(chazFundatory,(180,170))
        startbutton = Menu.Button("Play Game", screen, 180, 90, 200, 50)
        startbutton.draw(Menu.playButton)
import pygame
from pygame import *
import block_class
from block_class import Block
from GraphicsUtil import toplength, topwidth

blockWidth = 25
squareXpos = 0
squareYpos = 0


squareSurface = pygame.Surface((50,50))

squareSurface.set_colorkey((0,0,0))

B1 = Block(blockWidth,blockWidth, (255,0,0), squareXpos, squareYpos)

B1.groupDrawSquareBlock(squareSurface)


class squareBlock:
    def __init__(self):
        self.color = 1
        self.surface = squareSurface
        self.rotate = 0

    def points(self):   
        return [(0,0), (1,1), (1,0), (0,1)]                       

    # def groundDraw: 
Exemplo n.º 10
0
def expanding_block(filename, *, debug=False):
    """
Tests an image for copy-move forgery (a portion of an image has been copied
and then moved somewhere else within the image.)

Written by Efron Licht, based off the algorithm
"An efficient expanding block algorithm for image copy-move forgery detection"
by Gavin Lynch, Frank Y. Shih, and Hong-Yuan Mark Liao, and published in
Information Sciences 239 in 2013.

Free for noncommerical use or modification, but please retain the above credits.
Please ask for commerical use.

input:
    filename that contains an mxn image (color or grayscale)
    known valid formats: '.png', '.jpg'

output:
    imageConsideredModified, imgOut
    where imageConsideredModified is True | False
    if imageConsideredModified == True,     imgOut is the original image
    if imageConsideredModified == False,    imgOut is a (2m+8) x n x 3 image
    """
    """
    file IO and conversion to grayscale:
    """
    baseImg = io.imread(filename)

    try:
        # color.rgb2gray converts to doubles on unit scale (0<pixel<1)
        # so we rescale back to uint8

        img = np.uint8(255 * color.rgb2gray(baseImg))

    except ValueError as valError:
        shape = np.shape(baseImg)
        if shape[2] == 1:  # image is grayscale already
            img = baseImg
            # convert image into a a 3D array (psuedo-RGB) so as to not handle
            # so many unique cases later
            baseImg = np.uint8(255 * color.gray2rgb(baseImg))
        else:
            raise valError

    init = ExpandingBlockInit(img)

    rows = np.shape(img)[0] - init.blockSize
    cols = np.shape(img)[1] - init.blockSize
    blocks = ([
        Block(img, row, col, init) for row in range(rows)
        for col in range(cols)
    ])
    blocks = sorted(blocks, key=lambda block: block.variance)
    """
    remove elements with too low of variance to cut down on false positives
    due to bad white balance on source camera or areas of block color
    """

    blocks = [block for block in blocks if not block.tooLowVariance]
    """
    assign blocks as evenly as possible to groups
    """

    groups = [[] for x in range(init.numBuckets)]
    # we don't want to use * to avoid nasty by-reference bugs
    blocksPerBucket = len(blocks) / init.numBuckets
    group = 0
    count = 0

    for block in blocks:
        groups[group].append(block)
        count += 1

        if count > blocksPerBucket:
            group += 1
            count -= blocksPerBucket
    """
    assign groups to buckets
    """
    buckets = [None] * init.numBuckets
    for n in range(init.numBuckets):
        try:
            buckets[n] = groups[n - 1] + groups[n] + groups[n + 1]
        except IndexError:
            if n == init.numBuckets - 1:
                buckets[n] = groups[n - 1] + groups[n]
            else:
                raise IndexError
    """
    process buckets for pixel-to-pixel similiarity. see process_bucket
    """
    buckets = [process_bucket(bucket) for bucket in buckets]
    """
    recombine buckets after processing, removing empty buckets
    """
    blocks = [block for bucket in buckets for block in bucket]
    """
    if there are no blocks left, the image is clean
    """
    if len(blocks) == 0:
        imageConsideredModified = False
        return imageConsideredModified, baseImg
    #else
    imageConsideredModified = True
    """
    otherwise, we create a masked image to show where the
    modification occurs
    """
    mask = create_mask(blocks, baseImg, init)
    imgOut = np.uint8(write_mask(mask, baseImg))
    if debug:
        io.imshow(imgOut)
    return imageConsideredModified, imgOut
def expanding_block(filename, *, _debug=False):
    """
Tests an image for copy-move forgery (a portion of an image has been copied
and then moved somewhere else within the image.)

Written by Efron Licht, based off the algorithm
"An efficient expanding block algorithm for image copy-move forgery detection"
by Gavin Lynch, Frank Y. Shih, and Hong-Yuan Mark Liao, and published in
Information Sciences 239 in 2013.

Free for noncommerical use or modification, but please retain the above credits.
Please ask for commerical use.

input:
    filename that contains an mxn image (color or grayscale)
    known valid formats: '.png', '.jpg'

output:
    imageConsideredModified, imgOut
    where imageConsideredModified is True | False
    if imageConsideredModified == True,     imgOut is the original image
    if imageConsideredModified == False,    imgOut is a (2m+8) x n x 3 image
    """
    """ 
    helper functions
    """
    def _generate_groups(blocks):
        """ assign blocks within image evenly to groups"""
        group = []
        blocksPerGroup = len(blocks) / init.numBuckets
        group = 0
        count = 0

        for block in blocks:
            if len(group) >= blocksPerGroup:
                yield group
                count -= blocksPerGroup
                group = []
            group.append(block)
            count += 1
        if len(group) > 0:
            yield group

    def _generate_buckets(groups):
        """ assign blocks within groups to overlapping buckets """
        for n in range(len(groups)):
            try:
                bucket = groups[n - 1] + groups[n] + groups[n + 1]
            except IndexError:
                if n == init.numBuckets - 1:
                    bucket = groups[n - 1] + groups[n]
                else:
                    raise
            yield bucket

    """
    MAIN FUNCTION START
    """
    #0. file IO and conversion to grayscale:

    baseImg = io.imread(filename)

    try:
        # color.rgb2gray converts to doubles on unit scale (0<pixel<1)
        # so we rescale back to uint8

        img = np.uint8(255 * color.rgb2gray(baseImg))

    except ValueError:
        shape = np.shape(baseImg)
        if shape[2] == 1:  # image is grayscale already
            img = baseImg
            # convert image into a a 3D array (psuedo-RGB) so as to not handle
            # so many unique cases later
            baseImg = np.uint8(255 * color.gray2rgb(baseImg))
        else:
            raise

    init = ExpandingBlockInit(img)

    rows, cols, *_ = np.shape(img) - init.blockSize
    blocks = ((Block(img, row, col, init) for row in range(rows)
               for col in range(cols)))
    blocks = sorted(blocks, key=lambda block: block.variance)

    #1. remove elements with too low of variance to cut down on false positives
    #    due to bad white balance on source camera or areas of block color

    blocks = dropwhile(lambda block: block.tooLowVariance, blocks)

    #2. assign blocks as evenly as possible to groups
    groups = _generate_groups(blocks)

    #3. assign blocks in neighboring groups to overlapping buckets
    buckets = _generate_buckets(groups)

    #4. process buckets for pixel-to-pixel similiarity. see process_bucket
    buckets = (process_bucket(bucket) for bucket in buckets)

    #buckets now hold blocks that we think are modified.
    #5. recombine buckets after processing
    blocks = [block for bucket in buckets for block in bucket]
    #6a. Image is considered clean if no blocks left after processing
    if len(blocks) == 0:

        imageConsideredModified = False
        imgOut = baseImg
    #6b. If image is considered modified,create mask for image
    else:
        imageConsideredModified = True

        mask = create_mask(blocks, baseImg, init)
        #7b. Paint mask over image
        imgOut = np.uint8(write_mask(mask, baseImg))
    #8. Output.
    if _debug:
        io.imshow(imgOut)

    return imageConsideredModified, imgOut