This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 thread pool implementation. | |
| Parts of this module are derived from: | |
| http://code.activestate.com/recipes/203871-a-generic-programming-thread-pool/ | |
| """ | |
| import time |
This file contains hidden or 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
| call :sleep %~1 | |
| goto:eof | |
| :: ----------------------------------------------------------------------------- | |
| :sleep | |
| ping 127.1 -n 2 -w 1000 > NUL | |
| ping 127.1 -n %~1 -w 1000 > NUL | |
| goto:eof |