This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""A module that defines metaclasses for slotted "info" data types. | |
""" | |
class InfoMeta(type): | |
"""A metaclass for classes that declaratively defines fields in | |
advance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import unittest | |
class TestMaker(type): | |
"""For a class to assign its __metaclass__ to this type, the class | |
creation will look for methods that are prefixed with '_test{name}'. | |
The method is assumed to take two arguments (self and a boolean). | |
From that, two methods will be dynamically generated, with the names |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check(attr): | |
def _check_fn(fn): | |
"""Use this function as a method decorator. When decorated with this, a | |
method will only execute its body when its associated object's attribute | |
is defined (evaluates to True). | |
""" | |
def meth(self, *args, **kwargs): | |
if getattr(self, attr, None): | |
return fn(self, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
from ctypes.wintypes import * | |
class SYSTEMTIME(Structure): | |
"""See: WinBase.h""" | |
_fields_ = [ | |
('wYear', WORD), | |
('wMonth', WORD), | |
('wDayOfWeek', WORD), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scapy.all import * | |
# XXX: make sure conf.route6 includes the target IPv6 address in its route table; | |
# you can do so by first calling ping6 so that a neighbor solicitation is done | |
sip = 'fe80::20c:29ff:fe67:22c2' | |
dip = 'fe80::700d:da7e:80bb:aca9' | |
packets = fragment6(IPv6(src=sip, dst=dip) / IPv6ExtHdrFragment() / ICMPv6EchoRequest(data='A'*5000), 1024) | |
send(packets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.Cipher import AES, XOR # from pycrypto library (https://www.dlitz.net/software/pycrypto/) | |
block_size = AES.block_size | |
def decrypt(key, ciphertext): | |
# assume: len(key) == 16 bytes; PKCS5 padding scheme; len(IV) == 16 bytes | |
iv = ciphertext[:block_size] | |
ciph = ciphertext[block_size:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.Cipher import AES, XOR # from pycrypto library (https://www.dlitz.net/software/pycrypto/) | |
block_size = AES.block_size | |
def decrypt(key, ciphertext): | |
# assume: len(key) == len(IV) == 16 bytes; no padding | |
iv = ciphertext[:block_size] | |
ciph = ciphertext[block_size:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
"""An algorithm to calculate a hashing schema described in: | |
https://class.coursera.org/crypto-004/quiz/feedback?submission_id=193325 | |
""" | |
import io | |
import sys | |
import hashlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scapy.all import * | |
# change this to your test machine's MAC address | |
SELF_MAC = '00:0c:29:67:22:c2' | |
BCAST_MAC = 'ff:ff:ff:ff:ff:ff' | |
# this will send a PROBE ARP request packet to the supplied IP address argument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.profile: executed by the command interpreter for login shells. | |
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login | |
# exists. | |
# see /usr/share/doc/bash/examples/startup-files for examples. | |
# the files are located in the bash-doc package. | |
# the default umask is set in /etc/profile; for setting the umask | |
# for ssh logins, install and configure the libpam-umask package. | |
#umask 022 |