Beispiel #1
0
def test_known_key():
    cipher = Hill(alphabet, 4, key2)
    criptotext = cipher.cipher("UN MENSAJE CON Ñ")
    assert True
    assert criptotext == "PBYSQPJJRWSBCA"
    assert cipher.decipher(criptotext) == "UNMENSAJECONÑA"
    criptotext = cipher.cipher("UN MENSAJE DE LONGITUD PAR")
    assert criptotext == "PBYSQPJJSUAFSBFLTMBVRR"
def test_init():
    size = randint(4, 9)
    if size == 4:
        with pytest.raises(CryptographyException):
            cipher = Hill(alphabet, size, "DBAB")
    elif size == 9:
        with pytest.raises(CryptographyException):
            cipher = Hill(alphabet, size, "DDDABCEFG")
    else:
        with pytest.raises(CryptographyException):
            cipher = Hill(alphabet, size)
Beispiel #3
0
 def add_hills(self):
     for x in self.hillS:
         hill = Hill(self.screen, "small", 96, 64)
         hill.rect.x = x * 32
         hill.rect.y = self.settings.brick_y_offset - 64
         self.hills.append(hill)
     for x in self.hillL:
         hill = Hill(self.screen, "large", 160, 96)
         hill.rect.x = x * 32
         hill.rect.y = self.settings.brick_y_offset - 96
         self.hills.append(hill)
    def reset(self, lives: int, settings: dict, score: int):
        self._settings = settings
        self._arena = Arena((ARENA_W, ARENA_H))
        self._arena.add_to_score(score)
        Mountain(self._arena, (MOUNTAIN_X, MOUNTAIN_Y))
        Hill(self._arena, (HILL_X, HILL_Y), self._settings['level'])
        self._ground = Ground(self._arena, (GROUND_X, GROUND_Y), self._settings['difficulty'])
        self._start_time = time()
        self.bg_list = [Mountain, Hill, Ground]
        self._time_to_generate_alien = time()
        self._hero = []
        self._hero.append(Rover(self._arena, (ROVER_X, ROVER_Y), 1))
        if self._settings['mode'] == 'co-op':
            self._hero.append(Rover(self._arena, (ROVER_2_X, ROVER_2_Y), 2))

        self._start = time()
        self._playtime = 80
        self.hero_lives = lives
        self._aliens = []
        self._obstacles = []
        self._type_obstacles = [Rock, Hole]
        self._rand_x_bomb = 0
        self._time_to_generate_bomber = time()
        self._bomb_ready = False
        self._second = time()

        if self._settings['difficulty'] == 'Easy':
            self.OBS_RANGE = 400
        elif self._settings['difficulty'] == 'Normal':
            self.OBS_RANGE = 300
        else:
            self.OBS_RANGE = 200
Beispiel #5
0
class Picture:
    def __init__(self, width, height):
        self.mWidth = width
        self.mHeight = height
        self.mSky = Sky(width, height)
        self.mPlanet1 = Planet(200, 210, 215)
        self.mPlanet1.setColor(204, 204, 204)
        self.mMountain1 = Mountain(width, height)
        self.mCrater1 = Crater(40, 130, 100, 100)
        self.mCrater2 = Crater(35, 120, 50, 50)
        self.mCrater3 = Crater(90, 10, 90, 90)
        self.mCrater4 = Crater(250, 90, 100, 100)
        self.mCrack1 = Crack(290, 250)
        self.mCrack2 = Crack(285, 240)
        self.mHill1 = Hill(175, 400)
        self.mHill2 = Hill(300, 380)
        self.mHill3 = Hill(500, 450)
        self.mStar = Star(width, height)
        return

    def draw(self, surface):
        self.mSky.draw(surface)
        self.mPlanet1.draw(surface)
        self.mMountain1.draw(surface)
        self.mCrater1.draw(surface)
        self.mCrater2.draw(surface)
        self.mCrater3.draw(surface)
        self.mCrater4.draw(surface)
        self.mCrack1.draw(surface)
        self.mCrack2.draw(surface)
        self.mHill1.draw(surface)
        self.mHill2.draw(surface)
        self.mHill3.draw(surface)
        self.mStar.draw(surface)
        return
 def __init__(self, ciphers=None):
     self.available_ciphers = {
         'caesar': Caesar(),
         'keywordcipher': KeywordCipher(),
         'bifid': Bifid(),
         'hill': Hill()
     }
     self.one_time_pad = ''
     self.one_time_padded_msg = ''
     self.use_one_time_pad = False
     self.cipher = ''
     self.encrypt = False
     self.decrypt = False
     self.message = ''
     self.key = ''
     self.quit = False
    def generate_map(self, settings, screen, objects, background, mario):
        mario.x = 100
        mario.y = settings.ground_level - mario.height
        mario.rect.x = mario.x
        mario.rect.y = mario.y
        self.generate_ground(settings, screen, objects)

        background.add(
            Hill(settings, screen, 0,
                 settings.ground_level - settings.large_hill_height, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 9,
                  settings.brick_lenth * 3, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 12,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 16,
                 settings.ground_level - settings.brick_lenth - 2, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 16,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 20,
                  settings.ground_level - settings.brick_lenth * 15, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 22,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 20,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 21,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 22,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 23,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 24,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 23.5,
                 settings.ground_level - settings.brick_lenth, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 29,
                 settings.ground_level - settings.brick_lenth * 2, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 39,
                 settings.ground_level - settings.brick_lenth * 3, 2))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 47,
                 settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 58,
                 settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 28,
                  settings.ground_level - settings.brick_lenth * 12, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 37,
                  settings.ground_level - settings.brick_lenth * 15, 2))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 41.5,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 49,
                 settings.ground_level - settings.large_hill_height - 2, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 57,
                  settings.ground_level - settings.brick_lenth * 15, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 65,
                  settings.ground_level - settings.brick_lenth * 5, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 60.5,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 65,
                 settings.ground_level - settings.small_hill_height, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 68,
                  settings.ground_level - settings.brick_lenth * 15, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 72.5,
                 settings.ground_level - settings.brick_lenth, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 76,
                  settings.ground_level - settings.brick_lenth * 13, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 78,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 79,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 80,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 81,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 82,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 83,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 84,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 85,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 86,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 87,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 88,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 85,
                  settings.ground_level - settings.brick_lenth * 15, 2))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 92,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 93,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 94,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 95,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 95,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 90.5,
                 settings.ground_level - settings.brick_lenth, 2))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 97,
                 settings.ground_level - settings.large_hill_height - 2, 2))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 101,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 102,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 107,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 110,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 113,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 110,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 106,
                  settings.ground_level - settings.brick_lenth * 11, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 108.5,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 113,
                 settings.ground_level - settings.small_hill_height, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 119,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 116,
                  settings.ground_level - settings.brick_lenth * 12, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 122,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 123,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 124,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 129,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 130,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 131,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 132,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 130,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 131,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 120.5,
                 settings.ground_level - settings.brick_lenth, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 124,
                  settings.ground_level - settings.brick_lenth * 11, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 133,
                  settings.ground_level - settings.brick_lenth * 13, 2))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 138.5,
                 settings.ground_level - settings.brick_lenth, 2))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 145,
                 settings.ground_level - settings.large_hill_height, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 11, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 135,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 136,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 137,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 136,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 137,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 137,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 142,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 142,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 142,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 143,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 143,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 144,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 149,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 150,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 150,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 151,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 151,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 151,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 157,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 157,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 157,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 158,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 158,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 159,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 161,
                 settings.ground_level - settings.small_hill_height, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 164,
                  settings.ground_level - settings.brick_lenth * 13, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 172,
                  settings.ground_level - settings.brick_lenth * 11, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 181,
                  settings.ground_level - settings.brick_lenth * 13, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 201,
                  settings.ground_level - settings.brick_lenth * 11, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 167.5,
                 settings.ground_level - settings.brick_lenth, 1))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 193,
                 settings.ground_level - settings.large_hill_height, 2))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 209,
                 settings.ground_level - settings.small_hill_height, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 164,
                 settings.ground_level - settings.brick_lenth * 2, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 180,
                 settings.ground_level - settings.brick_lenth * 2, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 169,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 170,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 171,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 172,
                  settings.ground_level - settings.brick_lenth * 4, 3))

        objects.add(
            Brick(settings, screen, settings.brick_lenth * 182,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 183,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 183,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 184,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 184,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 184,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 7, 4))

        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 7, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 8, 4))

        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 7, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 8, 4))
        objects.add(
            Flag_Pole(settings, screen, settings.brick_lenth * 199,
                      settings.ground_level - settings.flag_pole_height, 1))
        objects.add(
            Castle(settings, screen, settings.brick_lenth * 203,
                   settings.ground_level - settings.small_castle_height, 1))
def test_random_key():
    cipher = Hill(alphabet, 4)
    c1 = cipher.cipher("UN MENSAJE CON Ñ")
    assert cipher.decipher(c1) == "UNMENSAJECONÑA"
    c2 = cipher.cipher("UN MENSAJE DE LONGITUD PAR")
    assert cipher.decipher(c2) == "UNMENSAJEDELONGITUDPAR"
Beispiel #9
0
                check = len(msg)%key.shape[1]
                while not is_invertible(key):
                    print("You have not entered a valid key. The key must be a K-square invertible matrix, where K is a factor of the length of the message. ")
                    key = input("The matrix you entered is not invertible. please enter the key here: ")
                    if key.lower() == 'exit':
                        sys.exit(1)
                    key = eval(key)
                if check==0:
                    condition = False

            except NameError:
                "You have not entered a valid key. The key must be a K-square invertible matrix, where K is a factor of the length of the message. "
                key = input("please enter the key here: ")
                if key.lower() == 'exit':
                    sys.exit(1)
                key = eval(key)
                check = len(msg)%key.shape[1]
                if check==0:
                    condition = False               


        hill = Hill()
        result = encrypt_decrypt(hill, msg,option,key)
    #Finally after decrypting the message you must remove the one-time pad so you can get the original message
    if option == "decrypt":
        result = onetime.decrypt(result,one_pad)
        print("Your decrypted message is: ", result)



Beispiel #10
0
from hill import Hill
import alphabet

if __name__ == "__main__":

    while (True):
        sentence = input("Enter the message to (de)crypt: ").lower()
        mode = input(
            "Do you want to Encrypt (E) or Decrypt(D) the previous message? ")
        key = input("Enter the matrix (format: a b; c d) : ")
        alphabet.offset = int(input("A=0 or A=1 ? "))

        hill = Hill(key)

        if not hill.key.is_valid():
            print("The key does not respect Hill format")
            exit()

        if mode == 'E':
            print("Crypted message : " + hill.encrypt(sentence))
        elif mode == 'D':
            print(hill.decrypt(sentence))

        stop = input("Do you want continue ? (Y/N) ")

        if (stop == 'N'):
            exit()